springcloud项目如何禁用三方依赖的拦截器
背景原始代码中有一个自定义的通用依赖这个依赖中有很多通用方法和拦截器供整个系统使用。需求禁用其中一个拦截器保留其他方法和拦截器过滤器等。拦截器介绍原有拦截器自己封装了一个jdkcom.a.b.c.A11Interceptor注解component继承HandlerInterceptorAdapter配置项com.a.b.c.d.A11ConfigurationConfiguration ComponentScan(basePackages {a.b.c.d.*, a.b.c.*}) public class A11Configuration implement WebMvcConfiger{ Autowired private A11Interceptor a11Interceptor; Override public void addInterceptors(InterceptorRegistry registry){ //将自定义拦截器加入 registry.addInterceptors(a11Interceptor); } } Component public class A11Interceptor extends HandlerInterceptorAdapter { // 拦截器内容 }在很多文章中想要禁用掉一些拦截器的用法主要有三个添加application.yaml配置spring.autoconfigure.excludecom.a.b.c.A11Interceptor启动类中增加注解SpringBootApplication(exclude {A1Configuration.class, A11Interceptor.class})这两种方法使用以后服务都无法启动报错不是自动注入的配置。原因上面两种方法只能排除自动注入的配置具体内容请自行查阅。最终我使用了同包同名拦截器配置类。在自己的服务中重新创建一个配置类com.a.b.c.d.A11Configuration根据拦截器优先级会优先走入自己配置的拦截器