问题:
springboot自定义拦截器里自动装配一直为null
解决:
不要在addInterceptors里手动new一个interceptor 改成下面这样
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
@Bean
public MyInterceptor myInterceptor() {
return new MyInterceptor();
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
String[] addPath = {"/**"};
registry.addInterceptor(myInterceptor()).addPathPatterns(addPath);
}
}