After the SpringBoot project introduces Swagger2, enter the address in the browser address: http://ip:port/swagger-ui.html
error:
Looking at the background console, I found this error:
WARN o.s.web.servlet.PageNotFound -No mapping for get /swagger-ui.html
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:
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.