拦截器中使用@Autowired注入为null时,是因为拦截器加载的时间点是先于SpringContext的,并且又在代码中使用了new HandlerInterceptorAdapter()
.也就是这个类完全没有交给Spring容器管理,那么内部使用了@Autowried也就是无效的。
1.在拦截器上加@Component注解
2.若1没用则在实现WebMvcConfigurer的类中以@Bean的形式交给spring容器管理
拦截器中使用@Autowired注入为null时,是因为拦截器加载的时间点是先于SpringContext的,并且又在代码中使用了new HandlerInterceptorAdapter()
.也就是这个类完全没有交给Spring容器管理,那么内部使用了@Autowried也就是无效的。
1.在拦截器上加@Component注解
2.若1没用则在实现WebMvcConfigurer的类中以@Bean的形式交给spring容器管理