SpringBoot使用Swagger2本來可以使用的,后來出現的異常No mapping for GET /swagger-ui.html,這個異常其實不用怎么解釋,說白了就是找不到了。
遇到這種情況請先查找,最近你所添加繼承了【WebMvcConfigurationSupport】的類
如果繼承了WebMvcConfigurationSupport,則在配置文件在中配置的相關內容會失效,需要重新指定靜態資源
需要重新指定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);
}
}