SpringBoot 3 整合Swagger3.0或Knife4j

本文介绍了SpringBoot3.0版本后如何集成SwaggerUI进行API文档管理和knife4j增强版的配置,包括添加依赖、自定义访问路径、注解迁移以及knife4j的基本认证设置。
摘要由CSDN通过智能技术生成

spring boot3.X之后整合swagger添加依赖为

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

默认访问路径:

 http://server:port/swagger-ui/index.html

简单配置 

springdoc:
  swagger-ui:
    # 自定义的文档界面访问路径。默认访问路径是/swagger-ui/index.html
    path: /springdoc
    # 一共三个值来控制操作和标记的默认展开设置。它可以是“list”(仅展开标记)、“full”(展开标记和操作)或“none”(不展开任何内容)。
    docExpansion: none
    # 控制“试用”请求的请求持续时间(毫秒)的显示。
    displayRequestDuration: true
    # 控制供应商扩展(x-)字段和操作、参数和架构值的显示。
    showExtensions: true
    # 控制参数的扩展名(pattern、maxLength、minLength、maximum、minminimum)字段和值的显示。
    showCommonExtensions: true
    # 禁用swagger用户界面默认petstore url。(从v1.4.1开始提供)。
    disable-swagger-default-url: true
  api-docs:
    # enabled the /v3/api-docs endpoint
    enabled: true
    # 自定义的文档api元数据访问路径。默认访问路径是/v3/api-docs
    #    path: /springdoc/api
    # 布尔值。在@Schema(名称name、标题title和说明description,三个属性)上启用属性解析程序。
    resolve-schema-properties: true

整合增强版swaggerKnife4jicon-default.png?t=N7T8https://mvnrepository.com/artifact/com.github.xiaoymin/knife4j-openapi3-jakarta-spring-boot-starter

引入依赖

<dependency>
    <groupId>com.github.xiaoymin</groupId>
    <artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
    <version>4.3.0</version>
</dependency>

 简单配置:

#springdoc分组配置可不加
#springdoc:
#  group-configs:
#    - group: '默认分组'
#      paths-to-match: '/**'
#      packages-to-scan: 根目录包名

#knife4j相关配置
knife4j:
  enable: true
  setting:
    language: zh_cn
    swagger-model-name: bean类的名称
  basic:
    enable: true
    # Basic认证用户名
    username: hgh
    # Basic认证密码
    password: a1234567

文档地址:

http://ip:port/doc.html

Swagger2.0到Swagger3.0常用注解变更 

swagger2OpenAPI 3注解位置
@Api@Tag(name = “接口类描述”)Controller 类上
@ApiOperation@Operation(summary =“接口方法描述”)Controller 方法上
@ApiImplicitParams@ParametersController 方法上
@ApiImplicitParam@Parameter(description=“参数描述”)Controller 方法上 @Parameters 里
@ApiParam@Parameter(description=“参数描述”)Controller 方法的参数上
@ApiIgnore@Parameter(hidden = true) 或 @Operation(hidden = true) 或 @Hidden
@ApiModel@Schema实体类上
@ApiModelProperty@Schema实体属性上

  • 10
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
The error message "Could not find artifact org.springframework.boot:spring-boot-starter-parent:pom:2.3.4 in central" indicates that the requested artifact (spring-boot-starter-parent version 2.3.4) could not be found in the Maven Central Repository. There could be a few reasons for this issue: 1. Network connectivity: Check your internet connection to ensure that your system can access the Maven Central Repository. 2. Incorrect dependency coordinates: Confirm that you have specified the correct group ID, artifact ID, and version for the dependency in your project's pom.xml file. 3. Temporary unavailability: Sometimes, certain artifacts may not be available temporarily in the Maven Central Repository. In such cases, you can try again later to see if the artifact becomes available. To resolve this issue, you can try the following steps: 1. Clear your local Maven repository: Delete the .m2 folder in your user directory (e.g., C:\Users\YourUserName\.m2) and then rebuild your project. 2. Update your dependency versions: Check if there is a newer version of the spring-boot-starter-parent available and update the version in your pom.xml accordingly. 3. Use a different repository: If the artifact is not available in the Maven Central Repository, you can check if it is hosted in a different repository. You can add the repository URL to your pom.xml file under the <repositories> section. Example: ```xml <repositories> <repository> <id>spring-milestone</id> <url>https://repo.spring.io/milestone</url> </repository> </repositories> ``` Please note that the specific steps to resolve this issue may vary depending on your project setup and configuration.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值