java springboot 整合 springfox-swagger 3.0
时间: 2023-06-28 16:04:35 浏览: 140
首先,在 `pom.xml` 文件中添加以下依赖:
```xml
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
```
接下来,在 Spring Boot 的启动类中添加 `@EnableSwagger2WebFlux` 注解:
```java
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebFlux;
@SpringBootApplication
@EnableSwagger2WebFlux
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
```
最后,在你的控制器中添加 Swagger 相关的注解,比如 `@Api` 和 `@ApiOperation`,示例如下:
```java
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@Api(tags = "示例接口")
public class ExampleController {
@GetMapping("/example")
@ApiOperation("示例接口")
public String example() {
return "Hello, Swagger!";
}
}
```
完成上述步骤后,启动应用程序并访问 http://localhost:8080/swagger-ui/ 即可查看 Swagger 文档。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)