其他分享
首页 > 其他分享> > 拦截器中自动装配没用

拦截器中自动装配没用

作者:互联网

问题:

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);
    }

}

标签:装配,拦截器,MyInterceptor,没用,myInterceptor,addPath,new,public
来源: https://blog.csdn.net/m0_52640724/article/details/122786233