@Autowired注入为null
注入为空原因:使用类未实例化!!
应该加@Component、@Service等注解
@Autowired注入为null的解决办法
1.在应用的Filter或Listener中使用了@Autowired ,
原因:因为Filter和Listener加载顺序优先于spring容器初始化实例,所以使用@Autowired肯定为null了~~
解决:用ApplicationContext根据bean名称(注意名称为实现类而不是接口)去获取bean,随便写个工具类即可
2.使用类没有加@Service注解等
3.springboot未扫描到。你写的@Service、@Componet、@Configuration、@Repository等Spring注解未被扫描到,例如:springboot的主类扫描规则 -> @ComponentScan扫描多个包配置
还没有评论,来说两句吧...