Swagger problem: No mapping for GET /swagger-ui.html error

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);
    }

}

insert image description here

Guess you like

Origin blog.csdn.net/qq_51447496/article/details/132536561