1. 版本升级
在修复Apache Tomcat
输入验证错误漏洞(CVE-2024-24549
)时,我把项目的SpringBoot
版本由2.6.13
升级到了3.3.7
,漏洞的问题解决了,又带来了新的问题。
2. 问题
2.1 SpringBoot 3.x的破坏性变更
SpringBoot 3.x
基于Spring Framework 6.x
,引入了Jakarta EE 9+
的命名空间,很多旧的包名发生了改变,如下图的javax.* -> jakarta.*
,会对项目原有代码做改动。
2.2 依赖版本不兼容
项目启动时没有找到接口对应的Bean
,但是代码在版本升级前是没问题的。
***************************
APPLICATION FAILED TO START
***************************
Description:
Field historyMapper in cool.tch.service.impl.HistoryServiceImpl required a bean of type 'cool.tch.mapper.HistoryMapper' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
在接口上使用了注解@Mapper
,mybatis-plus
的依赖如下。
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.3.1</version>
</dependency>
查看mybatis-plus
的git仓库发现,mybatis-plus
的依赖SpringBoot3
和SpringBoot2
是不一样的。
解决了mybatis-plus
的依赖问题后,发现分页查询功能有问题,分页功能使用的是pagehepler
。
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.4.1</version>
</dependency>
发现在v1.4.6的时候才兼容了SpringBoot3
。
至此问题已经解决,服务正常启动且基本功能正常。是否还有其他潜在的问题只能在之后发现了。
总之版本升级还需谨慎又谨慎。
以上。