SpringBoot解决swagger-ui/index.html访问报错404
最近在做一个项目,采用swagger3.0,项目启动起来后,访问swagger路径:http://localhost:8880/vdmpess-web/swagger-ui/index.html报404,原因是 WebMvcConfig 继承了 WebMvcConfigurationSupport,继承该类之后,则在配置文件在中配置的相关内容会失效,需要重新指定静态资源
需要重新指定swagger静态资源。
项目中swagger地址
解决方法
添加指定静态资源的地址
@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.
addResourceHandler("/swagger-ui/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/")
.resourceChain(false);
}
}