JeecgBoot 框架升级 Spring Boot 3.1.5 步骤
JEECG官方推出SpringBoot3分支:
https://github.com/jeecgboot/jeecg-boot/tree/springboot3
本次更新由于属于破坏式更新,有几个生态内的组件,无法进行找到平替或无法升级,目前尚不完善,部分功能选择直接注释的方式,以下为功能列表
- Online功能
- 积木报表功能
- 仪表盘功能
- spring cloud gateway 的 SentinelFilterContextConfig 过滤器
Spring Boot
从 2.7.10升级到3.1.5有以下几个点需要注意。
- 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-explain
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-version#22-spring-boot-3x
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](https://my.oschina.net/bean)
public GroupedOpenApi swaggerOpenApi() {
return GroupedOpenApi.builder()
.group("default")
.packagesToScan("org.jeecg")
.build();
}
[@Bean](https://my.oschina.net/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"))
);
}
// ---------------------------替换后---------------------
[@Bean](https://my.oschina.net/bean)
public GroupedOpenApi swaggerOpenApi() {
return GroupedOpenApi.builder()
.group("default")
.packagesToScan("org.jeecg")
.build();
}
[@Bean](https://my.oschina.net/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>