Spring Boot
从 2.7.10升级到3.1.5有以下几个点需要注意。
本次更新由于属于破坏式更新,有几个生态内的组件,无法进行找到平替或无法升级,选择直接进行注释的方式,以> 下为功能列表
- online 功能
- 积木报表功能
- spring cloud gateway 的 SentinelFilterContextConfig 过滤器
- JDK版本支持从JDK 17-19版本
- javax.servlet切换到jakarta.servlet
- spring.redis配置切换为spring.data.redis
- Spring Cloud 2022.0.4
- Spring Cloud Alibaba 2022.0.0.0
除以上三点外,其它都是平滑升级,不过这也只是相对于我们应用Spring Boot的用户来说。不过对于第二点,属于是破坏性升级了,需要将项目中引用的javax.servlet替换成jakarta.servlet。
spring boot升级参考文档:https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.0-Migration-Guide
spring cloud升级参考文档:https://docs.spring.io/spring-cloud/docs/current/reference/html/
spring cloud alibaba升级参考文档:https://sca.aliyun.com/zh-cn/docs/2022.0.0.0/overview/version...
Shiro
前面讲到由于Spring Boot内部的servlet包换掉了,jeecg框架使用shiro以及spring boot集成,所以shiro需要升级,不过还好shiro官方给这个点提供了支持,以下是shiro的升级替换。
需要注意的是,spring boot 3.1.5对jedis的版本做了提升,提升后shiro无法兼容,所以只能在项目进行降版本处理。
shiro升级参考文档:https://blog.csdn.net/weixin_43492211/article/details/131217344
<!--shiro-->
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring-boot-starter</artifactId>
<version>${shiro.version}</version>
<exclusions>
<exclusion>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- shiro-redis -->
<dependency>
<groupId>org.crazycake</groupId>
<artifactId>shiro-redis</artifactId>
<version>${shiro-redis.version}</version>
<exclusions>
<exclusion>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-core</artifactId>
</exclusion>
<exclusion>
<artifactId>checkstyle</artifactId>
<groupId>com.puppycrawl.tools</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- shiro 无法使用 spring boot 3.X 自带的jedis,降版本处理 -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring</artifactId>
<classifier>jakarta</classifier>
<version>${shiro.version}</version>
<!-- 排除仍使用了javax.servlet的依赖 -->
<exclusions>
<exclusion>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-web</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- 引入适配jakarta的依赖包 -->
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-core</artifactId>
<classifier>jakarta</classifier>
<version>${shiro.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-web</artifactId>
<classifier>jakarta</classifier>
<version>${shiro.version}</version>
<exclusions>
<exclusion>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-core</artifactId>
</exclusion>
</exclusions>
</dependency>
knife4j
knife4j对于spring boot 3.X版本提供了支持,不过相当于spring boot 2.X的版本来说,差异比较大,从springfox转换成了springdoc,不能做到平滑升级,以下是需要替换的注解列表.
knife4j升级参考文档:
https://doc.xiaominfo.com/docs/quick-start/start-knife4j-vers...
https://springdoc.org/#migrating-from-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")
同样在初始化文档对象上也有区别,以下前后替换
@Bean(value = "defaultApi2")
public Docket defaultApi2() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
//此包路径下的类,才生成接口文档
.apis(RequestHandlerSelectors.basePackage("org.jeecg"))
//加了ApiOperation注解的类,才生成接口文档
.apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
.paths(PathSelectors.any())
.build()
.securitySchemes(Collections.singletonList(securityScheme()))
.securityContexts(securityContexts())
.globalOperationParameters(setHeaderToken());
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
// //大标题
.title("JeecgBoot 后台服务API接口文档")
// 版本号
.version("1.0")
// .termsOfServiceUrl("NO terms of service")
// 描述
.description("后台API接口")
// 作者
.contact(new Contact("北京国炬信息技术有限公司","www.jeccg.com","jeecgos@163.com"))
.license("The Apache License, Version 2.0")
.licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html")
.build();
}
// ---------------------------替换后---------------------
@Bean
public GroupedOpenApi swaggerOpenApi() {
return GroupedOpenApi.builder()
.group("default")
.packagesToScan("org.jeecg")
.build();
}
@Bean
public OpenAPI customOpenAPI() {
return new OpenAPI()
.info(new Info()
.title("JeecgBoot 后台服务API接口文档")
.version("1.0")
.contact(new Contact().name("北京国炬信息技术有限公司").url("www.jeccg.com").email("jeecgos@163.com"))
.description( "后台API接口")
.termsOfService("NO terms of service")
.license(new License().name("Apache 2.0").url("http://www.apache.org/licenses/LICENSE-2.0.html"))
);
}
升级的maven地址:
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
<version>4.3.0</version>
</dependency>
在knife4j 4.X版本中,首次在对swagger文档与spring cloud gateway进行了整合,提供完整的解决方案,做到了开箱即用,以下是应用案例,在jeecg中也得到了升级。
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-gateway-spring-boot-starter</artifactId>
<version>4.3.0</version>
</dependency>
spring boot 3.x 生态增强平滑升级
以下为平滑升级,即更换版本即可,不需要做任何调整,jeecg框架调整如下
<!-- druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-3-starter</artifactId>
<version>1.2.20</version>
</dependency>
<!-- 动态数据源 -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>dynamic-datasource-spring-boot3-starter</artifactId>
<version>4.1.3</version>
</dependency>
<!-- spring boot-admin -->
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
<version>3.0.4</version>
</dependency>
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。