Swagger2 被拦截处理

时间:2025-03-21 09:35:59
@Configuration
public class MyWebConfigurer extends WebMvcConfigurationSupport {

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

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //配置登录拦截器
        (loginInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "//**", "//**");
    }

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