当前位置:   article > 正文

SpringBoot3.2.0和Springboot2版本整合Swagger_springboot3.2 swagger

springboot3.2 swagger

Springboot3.2.0版本中不在支持swagger2的格式。

以下提供springboot2版本和Springboot3版本下的swagger依赖

SpringBoot2.X 需要配置config

  1. 、、、、、、、、、这个有ui界面 这是springboot 2 项目 需要配置swagger2文件
  2. <!-- 引入 swagger-->
  3. <dependency>
  4. <groupId>io.springfox</groupId>
  5. <artifactId>springfox-swagger2</artifactId>
  6. <version>2.7.0</version>
  7. </dependency>
  8. <dependency>
  9. <groupId>io.springfox</groupId>
  10. <artifactId>springfox-swagger-ui</artifactId>
  11. <version>2.7.0</version>
  12. </dependency>

配置信息

  1. @Configuration
  2. @EnableSwagger2
  3. public class Swagger2Config {
  4. @Bean
  5. public Docket docket() {
  6. return new Docket(DocumentationType.SWAGGER_2);
  7. }
  8. }

Springboot3.X版本 无需任何配置

  1. 、、、、、、、、、、 这个是springboot3项目 没有任何配置直接使用
  2. <!-- 引入 swagger-->
  3. <dependency>
  4. <groupId>org.springdoc</groupId>
  5. <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
  6. <version>2.0.2</version>
  7. </dependency>
  8. <dependency>
  9. <groupId>org.springdoc</groupId>
  10. <artifactId>springdoc-openapi-starter-webmvc-api</artifactId>
  11. <version>2.0.2</version>
  12. </dependency>

 然后启动成功后直接登录 http://ip:post/swagger-ui.html即可

需要注意的是swagger中2版本和3版本的书写格式不同,用法完全相同

从Springfox迁移过来的,需要修改注解:

@Api → @Tag

@ApiIgnore → @Parameter(hidden = true) or @Operation(hidden = true) or @Hidden

@ApiImplicitParam → @Parameter

@ApiImplicitParams → @Parameters

@ApiModel → @Schema

@ApiModelProperty(hidden = true) → @Schema(accessMode = READ_ONLY)

@ApiModelProperty → @Schema

@ApiOperation(value = "foo", notes = "bar") → @Operation(summary = "foo", description = "bar")

@ApiParam → @Parameter

@ApiResponse(code = 404, message = "foo") → @ApiResponse(responseCode = "404", description = "foo")

正常情况下只需要注意 Api和ApiOreration  和 Tag 和Operation(summary = “XXX”)即可

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/939917
推荐阅读
相关标签
  

闽ICP备14008679号