Spring Boot 3 升级踩坑指南:从 2.7 到 3.3 的迁移记录

Spring Boot 3 Upgrade Guide: Migration Notes from 2.7 to 3.3

| David | 2026-08-28T18:33:14

最近把项目从 Spring Boot 2.7 升级到了 3.3,整个过程花了三天。记录一下遇到的兼容性问题和解决方案。

Documenting our three-day migration from Spring Boot 2.7 to 3.3, including compatibility issues and solutions.

Spring Boot 3 发布好久了,我们的项目一直拖着没升级。最近终于下定决心,花了三天时间完成了从 2.7 到 3.3 的迁移。 最大的变化:javax → jakarta 这个是最广为人知的 breaking change。所有 javax.* 包名都要改成 jakarta.*: // Before import javax.servlet.http.HttpServletRequest; import javax.persistence.Entity; import javax.validation.constraints.NotBlank; // After import jakarta.servlet.http.HttpServletRequest; import jakarta.persistence.Entity; import jakarta.validation.constraints.NotBlank; 用 IDE 的全局替换很快就搞定了,但是要注意第三方库的兼容性。我们用的一个老版本的 MyBatis-Plus 就不支持 jakarta,必须升级到 3.5.x。 Java 版本要求 Spring Boot 3 最低要求 Java 17。好在 Java 17 是 LTS,大部分公司应该都升级了。需要注意的是一些被移除的 API: SecurityManager 被弃用了 一些 sun.misc 下的内部 API 不能直接用了 如果用了 Lombok,确保版本 >= 1.18.30 Spring Security 变化 Spring Security 6 的配置方式变了不少: // Before (2.7) @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers("/api/public/**").permitAll() .anyRequest().authenticated(); } // After (3.3) @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { http.authorizeHttpRequests(auth -> auth .requestMatchers("/api/public/**").permitAll() .anyRequest().authenticated() ); return http.build(); } 配置属性变更 一些配置属性改名了: spring.redis.* → spring.data.redis.* spring.elasticsearch.* → spring.elasticsearch.uris server.max-http-header-size → server.max-http-request-header-size 建议 如果你也在考虑升级,建议先跑一下 spring-boot-properties-migrator,它会自动检测过时的配置并给出替代方案。升级前一定要确保测试覆盖率够高,我们有几个 bug 就是测试没覆盖到的边缘场景。


Completed a three-day migration from Spring Boot 2.7 to 3.3. Key changes documented. Major Changes javax.* → jakarta.* namespace migration (check third-party library compatibility) Java 17 minimum requirement (watch for removed APIs, update Lombok) Spring Security 6 configuration style changes Configuration property renames (spring.redis → spring.data.redis, etc.) Tip: Run spring-boot-properties-migrator before upgrading and ensure good test coverage.

← Back to News