现象:

springboot项目打成war包放在tomcat服务器启动,启动之后

在 controller层 @Autowired可以注入bean,而在filter中使用到的@Autowired,并未生效

 

原因分析:

1.打包之时没有忽略SpringBoot中集成的tomcat包,既然打war包放到tomcat中去跑,那组件就应该用tomcat服务器的

2.war包在tomcat服务器启动时,filter这一层不在Spring容器中

 

解决方案:

1.打包

springboot打war包,启动之后filter中无法@Autowired

springboot打war包,启动之后filter中无法@Autowired

2.通过上下文,重新获取bean

springboot打war包,启动之后filter中无法@Autowired

截图方便,复制不是很方便,复用的过程,就当帮助大家熟悉一下代码吧,XDDD

相关文章: