原项目使用组件:
- spring boot 2.3.1.RELEASE
- spring cloud Hoxton.SR3
- spring-webmvc
- spring-data-jpa
- hibernate 5
- swagger2
升级后的项目组件:
- spring boot 3.0.11
- spring cloud 2022.0.4
- spring-webmvc
- spring-data-jpa
- hibernate 6.1.7.Final
- springdoc-openapi(swagger3)
以下为升级后修改部分
spring boot3 jdk最低要求为17
javax依赖改为jakarta
具体包:
javax.persistence:javax.persistence-api -> jakarta.persistence:jakarta.persistence-api
javax.servlet:javax.servlet-api -> jakarta.servlet:jakarta.servlet-api
所有使用了这两个依赖的组件,都要升级道改为Jakarta的版本。
如hibernate使用了javax.persistence依赖,但hibernate6改为了Jakarta,升级到hibernate6即可。
若组件无Jakarta版本,只能更换组件了
hibernate5 改为hibernate6
对应的jackson hibernate包也要修改
com.fasterxml.jackson.datatype:jackson-datatype-hibernate5 改为
com.fasterxml.jackson.datatype:jackson-datatype-hibernate6
swagger2改为springdoc-openapi(swagger3)
新的swagger引入方式
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.2.0</version>
</dependency>
改变内容
swagger的注解全部修改
@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")
配置方式全部修改
原配置
@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 GroupedOpenApi publicApi() {
return GroupedOpenApi.builder()
.group("springshop-public")
.pathsToMatch("/public/**")
.build();
}
或更灵活的配置
@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"));
}
javax.xml.bind在jdk8以后被移除jdk
如果有使用到Jackson json序列化依赖,则需要显式增加依赖
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>