原因分析
spring.resources.add-mappings=false 为静态资源设置默认处理
spring.mvc.throw-exception-if-no-handler-found=true
这样可以将自定义全局404异常方便Restful使用
但是spring.resources.add-mappings=false会导致swagger也不能访问。
解决方法
在实现WebMvcConfigurer这个接口的类中加入下面的方法实现,指定swagger的静态资源处理
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/", "/static", "/public");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
}
注意:本文归作者所有,未经作者允许,不得转载