Spring Boot集成Swagger 访问失败 SpringBoot集成Swagger2遇到异常:请求不到swagger-ui.html.note

我们在使用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

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Adam`南帝·梁

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值