拦截器 标签

springboot拦截器自动注入为null解决办法和具体原因分析

  |   0 评论   |   0 浏览

最近在使用springboot拦截器的过程当中,发现无法注入service,提示NPE错误 问题相关代码 springboot拦截器注册方式: @Configuration public class MyWebMvcConfigurer implements WebMvcConfigurer { @Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(new SessionInterceptor()).excludePathPatterns("/static/").addPathPatterns("/"); } } 拦截器代码: public class SessionInterceptor implements HandlerInterceptor { @Autowired private IUserService userService; @Override public boolean preHandle(HttpServletReques....