我们在使用SpringBoot集成Swagger2中,访问:http://localhost/swagger-ui.html
问题描述:
No mapping found for HTTP request with URI [/swagger-ui.html] in DispatcherServlet with name ‘dispatcherServlet’
问题截图:
参考文章:
https://www.it610.com/article/1188228427770077184.htm
https://blog.csdn.net/riemann_/article/details/103604937
https://blog.csdn.net/guanfl/article/details/54617045 (Swagger Annotations)
https://blog.csdn.net/qq_27093465/article/details/78972010(mvc)
解决方案
这个错误,是因为静态资源路径映射问题导致。
我们在访问http://localhost/swagger-ui.html时,这个swagger-ui.html相关的所有前端静态文件都在springfox-swagger-ui-2.4.0.jar里面。目录如下:
SpringBoot自动配置本身并不会把/swagger-ui.html这个路径映射到对应的目录META-INF/resources/下面。我们加上这个映射即可。构建一个WebMvcConfig 类,代码如下:
package com.demo;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.an