Swagger2和Swagger3用法簡介
阿新 • • 發佈:2021-10-15
匯入需要的包
地址
Swagger2需要的包
1. Springfox Swagger2 <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>3.0.0</version> </dependency> 2. Springfox Swagger UI <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>3.0.0</version> </dependency>
Swagger3需要的包
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
編寫Springboot程式,訪問Swagger-ui.html
在SpringBoot啟動類上新增@EnableSwagger2
註解
注意:不管是swagger2還是swagger3,目前的註解都是@EnableSwagger2,還沒有更新。
@EnableSwagger2是springfox提供的液體個註解,代表swagger2相關的技術開啟。
會掃描當前類所在包,及子包中的所有型別中的註解。做swagger文件的定值。
Swagger2訪問地址:http://localhost:8080/swagger-ui.html
Swagger3訪問地址:http://localhost:8080/swagger-ui/ (注意斜槓)