升级到 spring boot 3.*
和jdk17
去除swagger-maven-plugin依赖
javax ->jakarta
idea->重构->迁移软件包和类->Java EE to Jakarta EE
commons-fileupload
替换为jakarta的实现
1 2 3 4 5 6
| <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-fileupload2-jakarta</artifactId> <version>2.0.0-M1</version> </dependency>
|
1 2 3 4 5 6 7 8 9 10 11
| <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> <exclusions> <exclusion> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> </exclusion> </exclusions> </dependency>
|
swagger迁移到springdoc
删除 springfox 和 swagger 2 依赖项。改为添加依赖项。springdoc-openapi-starter-webmvc-ui
1 2 3 4 5 6
| <dependency> <groupId>org.springdoc</groupId> <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId> <version>2.2.0</version> </dependency>
|
无需其他配置
这将自动将 swagger-ui 部署到 spring-boot 应用程序:
访问地址
request1 2
| # 默认请求地址 GET http://ip:port/swagger-ui/index.html
|
对于 HTML 格式的 swagger 文档的自定义路径,请在 spring-boot 配置文件中添加自定义 springdoc 属性:。
1 2
| springdoc.swagger-ui.path=/swagger-ui.html
|
将 swagger 2 注释替换为 swagger 3 注释(它已包含在依赖项中)。 swagger3注释的包是 .springdoc-openapi-starter-webmvc-uiio.swagger.v3.oas.annotations
@Api→@Tag
@ApiIgnore→或或@Parameter(hidden = true)@Operation(hidden = true)@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”)
此步骤是可选的:仅当您有多个 bean 时,才将它们替换为 bean。DocketGroupedOpenApi
以前:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| @Bean public Docket publicApi(){ return new Docket(DocumentationType.SWAGGER_2) .select() .apis(RequestHandlerSelectors.basePackage("org.github.springshop.web.public")) .paths(PathSelectors.regex("/public.*")) .build() .groupName("springshop-public") .apiInfo(apiInfo()); }
@Bean public Docket adminApi(){ return new Docket(DocumentationType.SWAGGER_2) .select() .apis(RequestHandlerSelectors.basePackage("org.github.springshop.web.admin")) .paths(PathSelectors.regex("/admin.*")) .apis(RequestHandlerSelectors.withMethodAnnotation(Admin.class)) .build() .groupName("springshop-admin") .apiInfo(apiInfo()); }
|
现在:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| @Bean public GroupedOpenApi publicApi(){ return GroupedOpenApi.builder() .group("springshop-public") .pathsToMatch("/public/**") .build(); } @Bean public GroupedOpenApi adminApi(){ return GroupedOpenApi.builder() .group("springshop-admin") .pathsToMatch("/admin/**") .addOpenApiMethodFilter(method->method.isAnnotationPresent(Admin.class)) .build(); }
|
如果你只有一个 - 删除它,而是将属性添加到你的 :Docketapplication.properties
1 2
| springdoc.packagesToScan=package1, package2 springdoc.pathsToMatch=/v1, /api/balance/**
|
添加类型的 bean。请参阅示例:OpenAPI
1 2 3 4 5 6 7 8 9 10 11
| @Bean public OpenAPI springShopOpenAPI(){ return new OpenAPI() .info(new Info().title("SpringShop API") .description("Spring shop sample application") .version("v0.0.1") .license(new License().name("Apache 2.0").url("http://springdoc.org"))) .externalDocs(new ExternalDocumentation() .description("SpringShop Wiki Documentation") .url("https://springshop.wiki.github.org/docs")); }
|
actuator集成
1 2
| springdoc.show-actuator=true
|
fastjson升级到fastjson2
1 2 3 4 5 6
| <dependency> <groupId>com.alibaba.fastjson2</groupId> <artifactId>fastjson2</artifactId> <version>2.0.38</version> </dependency>
|
参考资料