项目场景:
SpringBoot使用Swagger2本来可以使用的,后来出现的异常No mapping for GET /swagger-ui.html
问题描述:
最近添加继承了《WebMvcConfigurationSupport》了类,继承了WebMvcConfigurationSupport类,会使swagger配置文件中的相关配置失效,需重新指定静态资源到swagger
解决方案:
重新指定swagger静态资源
@Configuration
public class WebMvcConfigurer extends WebMvcConfigurationSupport {
/**
* 发现如果继承了WebMvcConfigurationSupport,则在yml中配置的相关内容会失效。 需要重新指定静态资源
*
* @param registry
*/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").addResourceLocations(
"classpath:/static/");
registry.addResourceHandler("swagger-ui.html").addResourceLocations(
"classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations(
"classpath:/META-INF/resources/webjars/");
super.addResourceHandlers(registry);
}
}