在springboot,swagger正常配置后正常访问即可
可是当项目的静态文件路径被修改后,
比如修改后
spring.http.multipart.location=…………..
就会发生访问不到的情况
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Wed Aug 09 11:02:44 CST 2017
There was an unexpected error (type=Not Found, status=404).
No message available
是因为swagger-ui.html 是在springfox-swagger-ui.jar里的,因为修改了路径Spring Boot不会自动把/swagger-ui.html这个路径映射到对应的目录META-INF/resources/下面。
所以我们修改springboot配置类,为swagger建立新的静态文件路径映射就可以了
@Configuration
public class WebMVCConfig extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}