继承WebMvcConfigurationSupport的过滤器导致Swagger地址不能访问

所以需要再自己定义的过滤器中配置:

@Configuration
public class InterceptorConfig extends WebMvcConfigurationSupport {

    @Autowired
    private JwtInterceptor jwtInterceptor;

    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
       registry.addInterceptor(jwtInterceptor)
               .addPathPatterns("/**")
               .excludePathPatterns("/**/login/**")
               .excludePathPatterns("/actuator/health/**")
               .excludePathPatterns("/v2/api-docs/**")
               .excludePathPatterns("/v2/api-docs-ext/**")
               .excludePathPatterns("/swagger-resources")
               .excludePathPatterns("/error/**")
               .excludePathPatterns("/webjars/**")
               .excludePathPatterns("/swagger-ui.html")
               .excludePathPatterns("/doc.html");
    }

    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**")
                .addResourceLocations("classpath:/static/");
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("doc.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
        super.addResourceHandlers(registry);
    }

    /**
     * 配置默认servlet处理
     */
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }

}

总结

在一个项目中WebMvcConfigurationSupport只能存在一个,多个的时候,只有一个会生效。(可能Swagger中也存在一个子类导致)

你可能感兴趣的:(Spring,cloud,java,spring,boot)