【SpringDoc】SpringBoot 3 swagger-ui.html 报404 SpringDoc 官方文档问题(可能)

本文针对 SpringBoot 3.x 版本!!

SpringDoc v2 官方文档:https://springdoc.org/v2/

首先

旧版本的 swagger 和 1.x 版本的SpringDoc 均不支持 SpringBoot 3,所以对于 SpringBoot3 如下的两种 Swagger 或 SpringDoc 依赖均不可用,注意,是不可用

<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-ui</artifactId>
    <version>x.x.x</version>
</dependency>
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>x.x.x</version>
</dependency>
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>x.x.x</version>
</dependency>

正确的 SpringDoc 依赖

<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
    <version>2.1.0</version>
</dependency>

其次(最坑人的地方)

无数的文章甚至官方文档都表示,swagger-ui 界面的网址是 http://server:port/swagger-ui.html,访问这个网址,一直是404,天王老子来了也是404,就算在 application.properties 中设置了如下内容,也不管用

springdoc.swagger-ui.path=/swagger-ui.html

但是打开 Demo Spring Boot 3 Web MVC with OpenAPI 3 这个官方提供的 Demo 后,显示的网址是 http://server:port/swagger-ui/index.html, 把网址换成这个,瞬间打开!!

所以,正确的解决办法就是,访问 http://server:port/swagger-ui/index.html

Swagger (SpringFox) 迁移到 SpringDoc 后注解写法补充

官方文档中仅给出了如下说明:

Replace swagger 2 annotations with swagger 3 annotations (it is already included with springdoc-openapi-starter-webmvc-ui dependency). Package for swagger 3 annotations is io.swagger.v3.oas.annotations.
@Api → @Tag
@ApiIgnore → @Parameter(hidden = true) or @Operation(hidden = true) or @Hidden
@ApiImplicitParam → @Parameter
@ApiImplicitParams → @Parameters
@ApiModel → @Schema
@ApiModelProperty(hidden = true) → @Schema(accessMode = READ_ONLY)
@ApiModelProperty → @Schema
@ApiOperation(value = “foo”, notes = “bar”) → @Operation(summary = “foo”, description = “bar”)
@ApiParam → @Parameter
@ApiResponse(code = 404, message = “foo”) → @ApiResponse(responseCode = “404”, description = “foo”)

但是 MyBatis-Plus-Generator 生成的代码,在 entity 属性上的注解方法是

@ApiModelProperty("密码")
private String password;

文档只告诉我,要把 @ApiModelProperty 改成 @Schema 改完就报错啊,汗。正确的改法如下:

@Schema(name = "password", description = "密码")
private String password;

其他待补充

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

叼辣条闯天涯

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

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

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

打赏作者

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

抵扣说明:

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

余额充值