本地环境准备
JDK21:
MAVEN 3.9.8:
修改<properties>标签中对于java编译版本的指定,
<java.version>21</java.version>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<source>21</source>
<target>21</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>3.3.5</version>
<configuration>
<mainClass>com.aexpec.ae.aesbackend.AesBackendApplication</mainClass>
</configuration>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
</execution>
<execution>
<id>build-info</id>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin>
组件包变化
事项 处理方案
spring-framwork 升级
javax 包名需批量更换为 jakarta
httpclient 升级
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
换为
import org.apache.hc.core5.http.NameValuePair;
import org.apache.hc.core5.http.message.BasicNameValuePair;
更多参考 :https://zhuanlan.zhihu.com/p/674084672
https://hc.apache.org/httpcomponents-client-5.4.x/migration-guide/migration-to-classic.html
CronTrigger
CronTrigger trigger1 = new CronTrigger(taskCorn);
return trigger1.nextExecutionTime(triggerContext).toInstant();
--> incompatible types: bad return type in lambda expression -->
return trigger1.nextExecution(triggerContext);
druid 连接池 druid-spring-boot-starter → druid-spring-boot-3-starter
mysql connector
mysql-connector-java -> mysql-connector-j
com.mysql mysql-connector-jmybatis-plus
额外引入 mybatis-plus-jsqlparser
PaginationInterceptor 配置方式需重写
swagger 升级为 springdoc-openapi
https://www.cnblogs.com/lhlyzh/p/15680716.html
reference: https://springdoc.org/#migrating-from-springfox
Migrate from Spring Cloud Sleuth to Micrometer Tracing
io.micrometer
micrometer-tracing-bridge-brave
logback中 MDC 占位符
-[%X{X-B3-TraceId}, %X{X-B3-SpanId}]
更新为
-[%X{traceId:-}, %X{spanId:-}]
上下文请求头传递需兼容两种形式
线程池的包装参考如下写法
@Bean
public TaskDecorator decorator() {
return new ContextPropagatingTaskDecorator();
}
@Bean
ThreadPoolTaskExecutor executor(ThreadPoolTaskExecutorBuilder builder, TaskDecorator td) {
return builder.threadNamePrefix("GTX-")
.taskDecorator(td)
.build();
}
mybatis
Mybatis 插件写法变更. 3.4.0 以后废弃了自行注入插件的方式, 采用聚合的形式进行处理
// before
@Bean
public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor().setCountSqlParser(new JsqlParserCountOptimize(true));
}
// after
// 需依赖 com.baomidou:mybatis-plus-jsqlparser
@Bean
public MybatisPlusInterceptor paginationInterceptor() {
MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(DbType.MYSQL);
mybatisPlusInterceptor.addInnerInterceptor(paginationInnerInterceptor);
return mybatisPlusInterceptor;
}
Mybatis 废弃注解变更
// before
@SqlParser(filter = true)
// after
@InterceptorIgnore(tenantLine = "true")
Mybatis mapper xml 关键字冲突, 新增了关键字 ur rs, 是因为升级后, 依赖的 JSqlParser 升级后添加了新的关键字
github.com/baomidou/my…
count() 返回类型变更, 从 Integer 变为了 Long, 这个部分对代码的改动也比较大
LambadaWarraper in() 等集合查询参数由数组改为了集合, 这里需要检查下各自代码中的改动
mail包
com.sun.mail
jakarta.mail
2.0.1
如果依赖了spring-boot-starter-mail,则不需要依赖上面的引用
contorller中类似RequestMapping 等注释
org.springframework.boot
spring-boot-starter-web
HttpClient5升级笔记--API篇 https://www.cnblogs.com/FunTester/p/17926418.html
poi升级至5.3.0
需注意poi-ooxml、poi-ooxml-schemas、poi-ooxml-lite、poi-ooxml-full这几个包的配套关系
reflink: https://poi.apache.org/help/faq.html
redission升级至3.39.0
(已改造模块:
cmp-rebate
cmp-dataworker
elp-user
cmp-campaign
css-common)
(无需改造模块:
elp-benefit
)
redission默认的codec从MarshallingCodec 变成了Kryo5Codec,为兼容老版本已缓存的数据可以正常get(反序列化)
POM需要新增2个jar,如下
org.jboss.marshalling jboss-marshalling 2.0.10.Final org.jboss.marshalling jboss-marshalling-river 2.0.10.FinalRedissonConfig里面(增加config.setCodec(new MarshallingCodec());):
@Bean
public RedissonClient redisson(RedisProperties redisProperties){
Config config = new Config();
...
...
config.setCodec(new MarshallingCodec());
return Redisson.create(config);
}
启动问题
issue 问题原因 处理方案
The dependencies of some of the beans in the application context form a cycle 循环依赖策略更新
增加如下配置
spring.main.allow-circular-references=true
上述配置无效时,可以尝试在对应依赖上加上 @Lazy 注解
需注意循环依赖下策略模式使用
InitializingBean 的afterPropertiesSet 机制,使用
applicationContext.getBeansOfType() 时可能因 其他Bean正在创建中无法去除正确的bean
redis配置文件格式变化 升级springboot3.x后redis的配置路径多了.data
原先:spring.redis.xxx
现在:spring.data.redis.xxx
配置文件问题
issue 问题原因 处理方案
server.max-http-header-size 无效 新版本细分了配置
server.max-http-request-header-size
server.max-http-post-size
升级后,即使自增主键上加了@TableId(type = IdType.AUTO)注解,insert语句也不会忽略该字段,导致插入报错
新版本默认为false
mybatis-plus.global-config.db-config.insert-ignore-auto-increment-column = true
额外事项:
aes 的 common模块,需要修改模块名, 增加jenkins 二方包 pipline
评论