1. 环境准备
1.1 确认 Spring Boot 版本
确保使用 Spring Boot 2.x 版本(推荐 2.5.x - 2.7.x)
1.2 确认项目结构
- Maven 项目
- Spring Boot 2.x
- 需要 API 文档功能
2. 依赖配置
2.1 添加 Knife4j 依赖
在 pom.xml 中添加:
<properties>
<knife4j.version>4.3.0</knife4j.version>
</properties>
<dependencies>
<!-- Knife4j OpenAPI3 增强依赖 -->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-openapi3-spring-boot-starter</artifactId>
<version>${knife4j.version}</version>
</dependency>
</dependencies>
2.2 移除旧版本 Swagger 依赖(如有)
确保移除以下旧依赖:
<!-- 需要移除的依赖 -->
<!-- <dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
</dependency> -->
注意:只保留 Knife4j 依赖,其他的 swagger 相关依赖不要保留,否则会出现冲突。

