Knife4j使用的三个问题,全是版本问题,聚合博客:
Knife4j请求文档异常 - bugDesigner的博客 springboot版本问题
解决SpringCloudGateway集成knife4j文档 - bugDesigner的博客 springcloud技术栈版本问题
版本
<!-- 文档-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-gateway-spring-boot-starter</artifactId>
<version>4.3.0</version>
</dependency>
<!-- knife4j-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
<version>4.1.0</version>
</dependency>
问题描述
之前将SpringCloud和SpringBoot版本升级到了springboot3和springcloud2023,具体参考这个微服务项目Java8升级指南 - bugDesigner的博客,这次又出现了兼容性问题,表现形式是:
访问ip+port+/v3/api-docs/swagger-config时返回的并不是需要的各个微服务的地址,而是下面的格式
{
"configUrl": "/v3/api-docs/swagger-config",
"oauth2RedirectUrl": "http://localhost:8901/webjars/swagger-ui/oauth2-redirect.html",
"url": "/v3/api-docs",
"validatorUrl": ""
}
因此就导致访问http:localhost:port/doc.html这个找不到每个微服务的地址,就显示个默认的分组,正常情况下是下面这样
{
"configUrl": "/v3/api-docs/swagger-config",
"oauth2RedirectUrl": "",
"operationsSorter": "alpha",
"tagsSorter": "alpha",
"urls": [
{
"name": "ischool-community",
"url": "/community/v3/api-docs",
"contextPath": "/community",
"id": "aXNjaG9vbC1jb21tdW5pdHkvY29tbXVuaXR5L3YzL2FwaS1kb2NzL2NvbW11bml0eQ==",
"serviceName": "ischool-community",
"discovered": true
},
{
"name": "ischool-user",
"url": "/user/v3/api-docs",
"contextPath": "/user",
"id": "aXNjaG9vbC11c2VyL3VzZXIvdjMvYXBpLWRvY3MvdXNlcg==",
"serviceName": "ischool-user",
"discovered": true
}
],
"validatorUrl": ""
}
解决方法
升级就可以了,全部升级到官方的最新版本
<!-- 文档-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-gateway-spring-boot-starter</artifactId>
<version>4.5.0</version>
</dependency>
<!-- knife4j-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
<version>4.5.0</version>
</dependency>
文章评论