SpringBoot版本升级到3.x后引发的问题

Tch
Tch
Published on 2025-03-02 / 18 Visits
0
0

1. 版本升级

在修复Apache Tomcat 输入验证错误漏洞(CVE-2024-24549)时,我把项目的SpringBoot版本由2.6.13升级到了3.3.7,漏洞的问题解决了,又带来了新的问题。

https://tch.cool/archives/pzjhNzp0

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)

在接口上使用了注解@Mappermybatis-plus的依赖如下。

<dependency>
  <groupId>com.baomidou</groupId>
  <artifactId>mybatis-plus-boot-starter</artifactId>
  <version>3.3.1</version>
</dependency>

查看mybatis-plus的git仓库发现,mybatis-plus的依赖SpringBoot3SpringBoot2是不一样的。

https://github.com/baomidou/mybatis-plus

解决了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

https://github.com/pagehelper/pagehelper-spring-boot

至此问题已经解决,服务正常启动且基本功能正常。是否还有其他潜在的问题只能在之后发现了。

总之版本升级还需谨慎又谨慎。

以上。


Comment