JDK8+SpringBoot2.x 升级 JDK 17 + Spring Boot 3.x 日志
修改pom.xml中的Java版本
<properties>
<java.version>17</java.version>
<!-- 添加JVM参数,保持兼容性 -->
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
这一步直接运行没有什么问题
Spring Boot 2.x → 3.x 迁移
修改父pom.xml的核心变更:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.5.0</version>
</parent>
<properties>
<!-- 升级相关依赖版本 -->
<!-- <log4j2.version>2.23.1</log4j2.version>
<druid.version>1.2.20</druid.version> 跟随Springboot日志-->
<swagger.version>2.2.0</swagger.version> <!-- SpringDoc替代 -->
<fastjson.version>2.0.51</fastjson.version>
<mapstruct.version>1.5.5.Final</mapstruct.version>
<mybatis-plus.version>3.5.6</mybatis-plus.version>
</properties>
需要修改的依赖项
移除或替换不兼容的依赖
<!-- 1. 替换Swagger为SpringDoc(OpenAPI 3) -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.6.0</version>
</dependency>
<!-- 2. 升级MySQL驱动(必需) -->
<!-- Spring Boot 3 已经不再管理 这个坐标:mysql:mysql-connector-java -->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>8.3.0</version>
<scope>runtime</scope>
</dependency>
<!-- 3. 升级其他核心依赖 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-3-starter</artifactId>
<version>${druid.version}</version>
</dependency>
<!-- 4. 升级POI -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.2.5</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.2.5</version>
</dependency>
<!-- 5. 升级knife4j(如果仍需使用) -->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
<version>4.4.0</version>
</dependency>
poi-ooxml-schemas包的问题:
Dependency 'org.apache.poi:poi-ooxml-schemas:5.2.3' not found
POI 5.x 以后结构变了
以前: poi 、poi-ooxml 、poi-ooxml-schemas
现在(5.x 开始):poi-ooxml 默认内置 精简版 schema
如果你确实需要完整版 schema:✔️ 用 poi-ooxml-full或✔️ 用 ooxml-schemas
目前:先把org.apache.poi:poi-ooxml-schemas:5.2.3 注释掉了。【此处需要后期注意下】
更新阿里云Maven仓库
阿里云 Maven 旧地址已经 停止维护 + http 被阻断
<repositories>
<repository>
<id>aliyun-maven</id>
<url>https://maven.aliyun.com/repository/public</url>
</repository>
<repository>
<id>central</id>
<url>https://repo1.maven.org/maven2/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>aliyun-maven</id>
<url>https://maven.aliyun.com/repository/public</url>
</pluginRepository>
</pluginRepositories>
代码层面的迁移工作
1.javax → jakarta 包迁移
# 使用IDE的批量替换或迁移工具
# 修改所有import javax.* 为 import jakarta.*
旧 新
jakarta.persistence jakarta.persistence
jakarta.servlet jakarta.servlet
javax.validation jakarta.validation
javax.ws.rs jakarta.ws.rs
javax.annotation jakarta.annotation
javax.xml.bind jakarta.xml.bind
Security配置更新
JPA实体注解更新
Servlet API相关类的更新
2.注释掉了SwaggerConfig类,不再使用Swagger
3.ImmutableList:Spring Boot 3 + JDK 17 中完全不需要 Guava,直接用 JDK 自带的即可,改用List
Swagger 注解包替换成 SpringDoc 的新版注解
import io.swagger.annotations.ApiModelProperty;替换为
import io.swagger.v3.oas.annotations.media.Schema;
@Schema(description = "xxx")
改为 @Schema(description = "xxx")
旧(Springfox) 新(SpringDoc / OpenAPI 3)
@Api @Tag
@ApiOperation @Operation
@ApiImplicitParam @Parameter
@ApiModel @Schema
@ApiModelProperty @Schema
RedisUtils代码修改
- 老版代码使用了 Guava 的 ImmutableList、Sets.newHashSet()、Lists.newArrayList() 等工具类
升级到 Spring Boot 3 + Java 17 后,没有引入 Guava
Spring Boot 3 已经推荐用 JDK 自带集合类替代 Guava
解决方法:
ImmutableList.of(...) → List.of(...)
Sets.newHashSet(list) → new HashSet<>(list)
Lists.newArrayList() → new ArrayList<>()
建议删除 Guava 依赖,全部用 JDK 集合
- RedisTemplate 泛型导致 delete / multiGet 报错
原因:
升级后,你把 RedisTemplate 泛型改成了 RedisTemplate<String, Object>
老代码里很多地方使用 Set 或 List 作为 key,类型不匹配
Spring Data Redis 的 ValueOperations<K,V>.multiGet(Collection keys) 要求泛型 K 与 RedisTemplate 一致
delete() 接收 String 或 Collection,Set 不匹配
解决方法:
所有 Redis key 统一使用 String 类型
Set → Set
multiGet(List) 直接传 List,不用转 Set
delete(Collection) 传 Set 或 List
- ConvertingCursor / scanDel 泛型问题
原因:
老版代码使用 ConvertingCursor 来自动反序列化 cursor
Spring Boot 3 + Spring Data Redis 泛型更加严格
executeWithStickyConnection 要求返回 Cursor<byte[]>,ConvertingCursor<byte[], String> 泛型不兼容
解决方法:
不使用 ConvertingCursor,返回原生 Cursor<byte[]>
循环时手动 deserialize → String key = redisTemplate.getStringSerializer().deserialize(cursor.next())
再调用 delete(key)
修改SpringSecurityConfig
找不到符号: 类 WebSecurityConfigurerAdapter
Spring Boot 3 + Spring Security 6 已经移除了 WebSecurityConfigurerAdapter
原因:Spring Security 推崇 基于组件的配置,用 SecurityFilterChain + PasswordEncoder + UserDetailsService 代替继承方式
SLF4J出问题
运行报错:SLF4J(W): No SLF4J providers were found.
这说明 Spring Boot 启动时找不到 StatusPrinter2 类,这是 Logback 相关类。
Logback 版本不兼容
你项目中 logback-classic:1.2.9 与 Spring Boot 3.5.0(Spring Boot 3 依赖 Spring Framework 6)不兼容。
Spring Boot 3.5.0 使用 Logback 1.4.x,StatusPrinter2 是 Logback 1.4 的新类,而 1.2.9 没有这个类。
SLF4J 冲突
Standard Commons Logging discovery in action with spring-jcl: please remove commons-logging.jar from classpath in order to avoid potential conflicts
SLF4J(W): No SLF4J providers were found.
SLF4J(W): Defaulting to no-operation (NOP) logger implementation
你的 classpath 里既有 commons-logging 又有老版本 SLF4J,导致日志系统混乱。
解决方案:彻底跟随 Spring Boot 3 的日志版本 --->删除 <log4j2.version>2.17.0</log4j2.version>
<logback.version>1.2.9</logback.version>
Mybatis-plus 冲突
报错:Invalid value type for attribute 'factoryBeanObjectType': java.lang.String
升级 Mybatis-Plus 版本为 3.5.5 版本即可,需要注意下 Maven 的坐标标识 是mybatis-plus-spring-boot3-starter,这点和SpringBoot 2 的依赖坐标mybatis-plus-boot-starter有所区别。
mvn package报错:Maven 使用的 JDK 不是 17
ERROR\] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.14.0:compile (default-compile) on project eladmin-common: Fatal error compiling: 无效的目标发行版: 17 解决方案:修改 MAVEN_HOME 下的 jdk 指向?但不能影响其他jdk8的项目 #### Spring Boot 启动时无法找到数据库连接配置 Spring Boot 3.x 不再自动识别 spring.datasource.druid.url,而是要求 标准的 Spring Boot 数据源属性 url、username、password 放在 spring.datasource 下,而不是 spring.datasource.druid.url。 其他 Druid 特有配置仍然可以保留,Spring Boot 3.x 会自动注入到 DruidDataSource。 #### Hibernate Dialect 类名 MySQL5InnoDBDialect 已经找不到了 Spring Boot 3.x 升级到了 Hibernate 6。 Hibernate 6 移除了老的 Dialect 类(如 MySQL5InnoDBDialect、MySQL5Dialect)。 解决方案:修改配置 如果你 不强制指定 Dialect,Spring Boot 3 + Hibernate 6 会根据数据库连接 URL 自动选择 Dialect: spring: jpa: hibernate: ddl-auto: none (这个不能乱开,控制 JPA 启动时是否自动创建/更新/验证表结构) show-sql: true #### spring Data JPA 与 JSQLParser 版本不兼容 Spring Data JPA 3.5.0 里的 JSqlParserQueryEnhancer 调用了 Select.getPlainSelect()。 你引入的 JSQLParser 版本是 4.6。----\>发现是在mybatis-plus-spring-boot3-starter(3.5.5)里引入了jsqlparser的4.6 但在 JSQLParser 4.x 中,Select.getPlainSelect() 方法已经 被移除或改名。 因此运行时报 NoSuchMethodError。 把mybatis-plus-spring-boot3-starter升到 3.5.15 问题解决了 #### RedisTemplate that could not be found 前面RedisUtils里把RedisTemplate\