SpringMvc(ssm)加入拦截器后swagger不能访问问题

原文链接:blog.ouyangsihai.cn >> SpringMvc(ssm)加入拦截器后swagger不能访问问题

只需要加入下面的配置即可。

@Configuration
public class MyWebAppConfig extends WebMvcConfigurationSupport {

    @Bean
    LoginInterceptor localInterceptor() {
        return new LoginInterceptor();
    }

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

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

你可能感兴趣的:(SpringMvc(ssm)加入拦截器后swagger不能访问问题)