Swagger problem: No mapping for GET /swagger-ui.html error
Introduction: This article explains the solution to the error of No mapping for GET /swagger-ui.html.
Just need to inherit WebMvcConfigurer for the configuration class of SwaggerConfig, and then add the overload method.
@Configuration
@EnableWebMvc
@EnableSwagger2 // 开启Swagger2
public class SwaggerConfig implements WebMvcConfigurer {
@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/");
WebMvcConfigurer.super.addResourceHandlers(registry);
}
}