使用拦截器调用服务出现空指针异常解决
在使用拦截器的时候,发现调用Service会出现空指针异常,查看原因,原来是
使用new关键字导致无法注入
@Configuration
public class WebConfiguer implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new UserLoginHanderInterceptors()).addPathPatterns("/**");
}
}
改正:
将拦截器加入@Component
自动注入WebConfig