Swagger: Whitelabel Error Page.No mapping for GET /swagger-ui.html

created at 05-29-2022 views: 46

problem

After the SpringBoot project introduces Swagger2, enter the address in the browser address: http://ip:port/swagger-ui.html error:

Whitelabel Error Page

Looking at the background console, I found this error:

WARN o.s.web.servlet.PageNotFound -No mapping for get /swagger-ui.html

reason and solution

After analysis, it is found that the default Swagger static resource is overwritten and the configuration is missing because the configuration annotation class (@Configuration) in the project inherits WebMvcConfigurationSupport.

You can explicitly add the following swagger static resources in the inheritance configuration class:

modification

registry.addResourceHandler("swagger-ui.html")
        .addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**")
        .addResourceLocations("classpath:/META-INF/resources/webjars/");

Package, deploy and restart, and it will work.

created at:05-29-2022
edited at: 05-30-2022: