Filter过滤器中springboot自动装配失效

过滤器中自动装配了其它类,在idea中调试的时候没有出任何问题,但是打包部署到tomcat,运行到过滤器代码时报错,经过检查是自动装配的类为null。造成这种的原因是因为部署到tomcat时,过滤器是由tomcat管理的,不归springboot管。解决方式就是自己去springboot的bean管理器中获取需要的类。

1 jurisdictionMapper = WebApplicationContextUtils.getRequiredWebApplicationContext(request.getServletContext())
2                 .getBean(JurisdictionMapper.class);

 

posted @ 2022-06-10 19:44  听雷雨声  阅读(225)  评论(0编辑  收藏  举报