增加拦截器后发现swagger无法访问,是因为swagger的内置接口被拦截了

  • 继承WebMvcConfigurationSupport类后重写addResourceHandlers方法

  • 重写 addResourceHandlers 方法如下:

1
2
3
4
5
6
7
8
9
10
11
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/static/**")
.addResourceLocations("classpath:/static/");
registry.addResourceHandler("/templates/**")
.addResourceLocations("classpath:/templates/");
registry.addResourceHandler("swagger-ui.html").addResourceLocations(
"classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations(
"classpath:/META-INF/resources/webjars/");
}