1. 程式人生 > >SpringBoot配置攔截器後Swagger被攔截的解決辦法

SpringBoot配置攔截器後Swagger被攔截的解決辦法

只需要在註冊攔截路徑時去處Swagger的路徑即可
    重點在於Swagger的路徑,同Swagger報404的配置的靜態資源的路徑稍有不同,這裡的配置具體如下

@Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(interceptor).addPathPatterns("/**")
            .excludePathPatterns("/user/logIn").excludePathPatterns("/user/logOut"
) .excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**"); super.addInterceptors(registry); }