Swagger2 和 Swagger3 的不同
SpringBoot 整合 Swagger3 和 Swagger2 的主要區別如下:
區別一:引入不同的依賴
- 如果使用的是 Swagger 3
<dependency><groupId>io.springfox</groupId><artifactId>springfox-boot-starter</artifactId><version>3.0.0</version>
</dependency>
- 如果使用的是 Swagger 2
<dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger2</artifactId><version>2.9.2</version>
</dependency><dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger-ui</artifactId><version>2.9.2</version>
</dependency>
區別二:使用不同的注解
- 如果使用的是 Swagger 3
@Configuration
@EnableOpenApi // 可省略
public class SwaggerConfig {...
}
- 如果使用的是 Swagger 2
@Configuration
@EnableSwagger2
public class SwaggerConfig {...
}
區別三:使用不同的枚舉變量
- 如果使用的是 Swagger 3
new Docket(DocumentationType.OAS_30)
- 如果使用的是 Swagger 2
new Docket(DocumentationType.SWAGGER_2)
區別四:訪問不同的 swagger ui 頁面路徑
-
如果使用的是 Swagger 3:http://localhost:8080/swagger-ui/index.html
-
如果使用的是 Swagger 2:http://localhost:8080/swagger-ui.html
區別五:暴露的 json 接口不同
-
如果使用的是 Swagger 3:http://localhost:8080/v3/api-docs
-
如果使用的是 Swagger 2:http://localhost:8080/v2/api-docs