Java 25 and Spring Boot 4 Migration: A Field Guide to the Silent Breakages
Two services of mine finally went from Boot 3.5 to 4.1, and the JDK went from 21 to 25. It dragged on for over a week, but the actual coding time wasn't much; most of it went into figuring out why "it compiles, starts up fine, but behaves wrong."
This article follows the order I went through at the time. Where I got stuck, what the errors looked like, and how I eventually worked around them - all noted down. The technical conclusions were double-checked against official documents afterward, but the narrative is the real path at the time, including the places where I first misjudged.
Let me set the timeline first, so readers don't compare against old articles: JDK 25 is the LTS version that went GA on September 16, 2025; Boot 4.0 was released on November 20, 2025; Boot 4.1 on June 10, 2026; Spring AI 2.0 went GA on June 12, and 2.1 is a matter for November 20, 2026. This time I upgraded to 4.1, and incidentally moved Spring AI from 1.1 to 2.0 - 2.1 just came out and I haven't dared to follow it yet.
I set myself a rule from the start: change only one variable at a time
The trigger isn't complicated: open-source support for 3.5 ends at the end of June 2026, so staying on 3.x means eating patch losses. Plus JDK 21 is nearing the end of maintenance, so I had to move anyway.
But I didn't dare move them together. Anyone who has been burned knows: if you upgrade JDK and Boot simultaneously, once an error appears, the stack is full of classes you've never seen, and you can't tell whether it's a bytecode-level issue or a framework-level one. So I split it into two commits - first upgrade JDK while Boot stays put; once that runs stable, upgrade Boot.
That decision later saved me once. After upgrading JDK 25, the app did change, but because Boot wasn't touched, I could be sure the problem was on the JDK side, and the investigation target was clear. If I had bundled everything at once for convenience, I'd probably be debugging until I broke down.
Also, let me correct a rumor I initially believed too: Boot 4 requires Java 21. I checked the official release notes; the minimum is still 17, and Java 25 is only first-class citizen support. And the javax to jakarta change was completed in the Boot 3 era, and has nothing to do with 3→4. I've seen people in upgrade forums asking "should I change package names too?" - that's the wrong direction.
JDK 21 to 25: I thought it would be calm
Actually, upgrading JDK went smoother than expected. Compile, tests, start - one round and only a few extra warnings.
But calm doesn't mean no pitfalls; the pitfalls are just buried elsewhere.
I first sorted out the upgrade benefits, because I found that many online articles never check official sources. Looking at OpenJDK's JDK 25 page and the "JEPs integrated since JDK 21" list, a few that relate to my daily work:
JEP 506 Scoped Values only went Final in 25. I'd played with the preview on JDK 21, so after upgrading I went back to check, and found a small change in the final version - ScopedValue.orElse no longer accepts a null parameter. If someone used the preview API form, this will break.
JEP 491 (virtual threads no longer pin) landed in JDK 24, which is a real win for high-concurrency services.
JEP 519 Compact Object Headers and JEP 521 Generational Shenandoah became "product features" in 25. Note, "product features" not "enabled by default" - JEP 519's text explicitly says it doesn't intend to be the default object header layout, and JEP 521 also says Shenandoah still defaults to single-generational. I needed to explicitly add the flags in the startup parameters:
# JDK 24 requires two flags
java -XX:+UnlockExperimentalVMOptions -XX:+UseCompactObjectHeaders ...
# JDK 25 removes UnlockExperimentalVMOptions, but still needs explicit enablement
java -XX:+UseCompactObjectHeaders ...
The official docs give nice performance numbers - in a SPECjbb2015 scenario, heap usage down 22%, CPU down 8%, another scenario GC count down 15%. But I didn't take them at face value, because those are specific benchmarks. I ran my own services with the flags on and off through load tests before deciding. Treat those numbers as promises.
What actually took my time was compatibility investigation.
Across four versions, what actually blocks you isn't new syntax but security policy tightening and internal API sealing. The one that stuck most was sun.misc.Unsafe: JEP 471 (JDK 23) marked its memory-access methods as deprecated for removal, and JEP 498 (JDK 24) made their use emit a warning. We have an old utility class that had hand-rolled off-heap memory, and it popped up in the logs.
Here I made my first mistake. I instinctively wanted to use --illegal-access=warn to see who was calling it, but the JVM didn't recognize it - that option was deprecated in JDK 16 and removed in 17; my brain was still in JDK 8 mode. Later I used jdeps to scan the dependency tree and located it:
jdeps --jdk-internals --multi-release 25 -recursive app.jar
I added this to my pre-upgrade checklist. Also, if you see warnings, don't rush to add --add-opens to open everything up; that's like canceling out the upgrade's purpose.
Two other things worth knowing ahead of time: JEP 486 permanently disables the Security Manager, so if any system relies on it for sandboxing, you need an external isolation solution. JEP 503 removes the 32-bit x86 port, so some old CI images still carrying 32-bit JDKs will bite you.
There's another easily confused thing I'll call out separately, because I fell into it myself: many online articles list JEP 500 (final-field reflection warnings), 504 (removing Applet), 516 (AOT object cache), 517 (HTTP/3), 522 (G1 throughput optimization), 525 (structured concurrency sixth preview), 526 (lazy constants) as "JDK 25 new features."
I checked each one against the OpenJDK page, and all of these belong to JDK 26 (GA on March 17, 2026), not 25. Structured concurrency was still the fifth preview in 25, and only the sixth in 26. The cost of mislabeling versions is real - I initially assumed that upgrading to 25 would show final-field reflection warnings, and searched in the wrong direction for half a day, when that only starts in 26.
The lesson from this: spend half an hour before the upgrade reading the official JEP pages, which saves more time than reading ten second-hand articles.
Boot 3.5 to 4.0: the real hard fight
First, a principle I strictly followed: first upgrade to the latest patch of 3.5, clean up all deprecated things, then switch to 4.0.
The first item in the official migration guide says exactly this. The reason is practical - deprecated APIs get actually deleted in 4.0. Zeroing the warnings on 3.5 is equivalent to handling what 4.0 will remove early. I've seen people jump straight from 3.0 to 4.0, facing both old bugs and new breaking changes at once, with no way to attribute the cause.
To understand Boot 4's changes, one main thread is enough: modularization. The official blog gave a number: in Boot 1.0, spring-boot-autoconfigure was only 182 KiB, and by 3.5 it had grown to 2 MiB. The reason is that every supported technology adds a batch of auto-configuration classes, 99% of which your project doesn't use.
Boot 4 splits the big jar into small modules. All the subsequent pitfalls are chain reactions from this main thread: starter renames, auto-configuration no longer triggering implicitly, test dependencies needing to be filled in, package name regrouping. Once you understand that causality, you don't need to memorize the upgrade checklist.
One more thing to do before starting: investigate the version coupling of third-party libraries. I almost missed this step because it doesn't necessarily fail at compile time. Key versions I'll list here to save readers detours:
- MyBatis-Plus: The official release notes show that Boot 4 support was added incrementally on the 3.5.x line - v3.5.18's entry says "support SpringBoot 4.0.0" and "support Jackson 3.0", and v3.5.18.1 (2026-10-27) explicitly lists "isolate starter configurations and adapt Spring Boot 4". Note that it also provides a separate artifact like
mybatis-plus-spring-boot4-starterand manages it in the BOM. So this isn't just "bump a major version number"; you need to see which starter line you're on. - Lombok: The official changelog is clear - JDK 25 support starts with v1.18.40 (original text: "PLATFORM: JDK25 support added"), JDK 24 support is v1.18.38. Before upgrading JDK, confirm the Lombok plugin in your IDE also follows; otherwise compilation passes but the IDE is a sea of red.
- REST Assured: Boot 4 / Framework 7 is based on Groovy 5, and Spring REST Docs 4.0 removed support for REST Assured because the latter wasn't compatible with Groovy 5 at the time. This claim comes from compiled public upgrade guides; I recommend checking the official Spring REST Docs documentation for your target version. If your test stack depends on REST Assured, you need to decide on a replacement before upgrading.
The biggest pitfall I hit with versions was initially copying numbers from online "support matrices" and finding several were wrong. In the end I had to go to GitHub release notes and official changelogs and check them one by one - whenever you can find the original text, don't use second-hand numbers. These I've verified against the original, but the coverage is limited; run your project's other libraries through the same process.
Flyway silently not running: this one got me stuck the longest
After the upgrade the service started fine and endpoints were callable. Then a query said "table doesn't exist" and I realized the database was never initialized.
Reason: in Boot 3, as long as flyway-core is on the classpath, auto-configuration kicks in; Boot 4 moved Flyway's auto-configuration to a separate spring-boot-flyway module, so just having flyway-core doesn't execute anything, and even the flyway_schema_history table isn't created.
It doesn't error; it just silently doesn't run. This is the most insidious change in Boot 4 in my opinion.
Fix is straightforward:
<!-- Boot 3 -->
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<!-- Boot 4 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-flyway</artifactId>
</dependency>
But I didn't consider it done after fixing the dependency. I did three layers of verification: mvn dependency:tree | grep flyway to confirm the starter is in the dependency tree; --debug startup to see whether FlywayAutoConfiguration matches in the auto-configuration condition report; finally, directly connecting to the database to check the table.
I've repeated this lesson many times to others: compilation passing is not migration complete, and successful startup does not mean the database migration ran.
Jackson 3's date format: nearly a silent contract break
Boot 4 prefers Jackson 3, with package names moved from com.fasterxml.jackson to tools.jackson - though jackson-annotations stays in the old package, which is an easy detail to overlook.
The recommended approach is to migrate from the mutable ObjectMapper to the immutable JsonMapper, which is the preferred type for Boot 4's auto-configuration. Jackson2ObjectMapperBuilderCustomizer becomes JsonMapperBuilderCustomizer, and the package becomes org.springframework.boot.jackson.autoconfigure. Because the mapper is immutable, all customization must happen at the builder stage; you can no longer call setTimeZone(...) on a created instance.
What really bites is the date format: Jackson 3 defaults to writing ISO-8601 strings.
I initially thought it was fine, because the mapper Spring creates in Boot 3 is typically already ISO. But a scan through the code revealed several places where I'd done new ObjectMapper() myself - those changed output format, and downstream systems aren't under our control. That's a silent contract change; you can't find it without a diff.
The crude but effective method I used: hit a real endpoint before and after, and diff directly.
curl -s http://localhost:8080/api/order/1 > before.json # before upgrade
curl -s http://localhost:8080/api/order/1 > after.json # after upgrade
diff before.json after.json
Focus on dates, nulls, and default values. Boot 4 provides a transition switch spring.jackson.use-jackson2-defaults: true that can hold for a while, but don't rely on it long-term.
Places that turn red at compile time: the ones that save you the most worry
HttpHeaders in Spring Framework 7 no longer implements MultiValueMap, as the Javadoc clearly states. I had a utility method that passed HttpHeaders as a Map; compilation failed directly - fixed by returning HttpHeaders directly. If a third-party SDK only accepts MultiValueMap, bridge with toMultiValueMap() at the adapter layer; don't treat it as a permanent design.
@MockBean was deprecated in 3.4 and removed in 4.0; switch to @MockitoBean. Annotations like @WebMvcTest also moved packages. These errors look like dependency breakage but are actually class relocations; don't investigate in the direction of version conflicts.
Undertow was removed. The official reason is that Boot 4 requires Servlet 6.1 as a baseline, and Undertow wasn't compatible at the time. We weren't using Undertow, but another team service was. After switching to Tomcat, thread pools, request limits, and access logs all need full re-verification - these settings don't transfer between containers.
There's also the custom starter matter. We have an internal starter that serves both 3.x and 4.x with one artifact. The official stance is clear that this is not recommended; you need to split branches or split artifacts. This isn't a temporary compile error you can work around; it's an architectural decision to make before upgrading.
Automated migration tool: I used it but didn't fully trust it
I tried OpenRewrite's upgradeSpringBoot_4_0 recipe. Community tests show it only does minor version bumps and mis-types ObjectMapper - my results were similar; mechanical replacement saved a lot of manual labor, but types were indeed changed wrongly.
My usage: after running, review git diff item by item, paying special attention to whether types got twisted. The tool can't judge whether your API contract needs byte-for-byte compatibility, whether deployment assumptions changed, or whether security rules can be altered.
Transitioning large projects: classic starter
One of our services has too many tangled dependencies to change all at once. Boot 4 provides spring-boot-starter-classic and spring-boot-starter-test-classic that restore a broad auto-configuration coverage close to old versions, letting you get a green build first.
The official docs are clear: these are transition tools - they aggregate all modules but don't propagate their transitive dependencies, and explicitly recommend "finally migrate away".
I treated it as scaffolding: get the service running first, then swap to modular starters in batches. If the bridge stays forever, it becomes architecture. I've seen that pitfall more than once.
Version coupling for 4.1 and Spring AI
After 4.0 was stable, I went up to 4.1. What attracted me was native gRPC support and the SSRF mitigation for the HTTP Client. We have a scenario that dynamically accesses external URLs based on model output, so SSRF went from a paper risk to a real threat; this capability is exactly what fits.
The specific feature list I checked against the Boot 4.1 release notes; community article summaries are only usable as an index.
If you use Spring AI, think about the version relationship together. Spring AI 2.0's official statement is that it's designed for Boot 4.0 / 4.1 and Framework 7; 2.1 GA'd on November 20, 2026, and is based on Boot 4.2. So:
- Staying on Boot 3.5: match with Spring AI 1.1.x, and move together when the AI part is ready;
- Going to Boot 4.0/4.1: match with Spring AI 2.0.x;
- Wanting Spring AI 2.1: upgrade Boot to 4.2 together.
One detail easily misled by old checklists: starter renames mostly happened in the Spring AI 1.0 era. spring-ai-openai-spring-boot-starter is the old name; in 1.0/2.0 the mainstream is already spring-ai-starter-model-openai. Don't copy those old online lists.
In Spring AI 2.0 there's a refactor I found valuable: the tool-calling loop used to be buried inside each ChatModel, with no external control; 2.0 promotes this loop into the advisor chain, making it a first-class composable component. If you previously wrote a custom tool-calling loop, change it during this upgrade; future maintenance becomes much easier.
What I validated after the upgrade
My checklist is these items, all summarized after stepping on the rakes:
- Database migration actually ran: three layers - dependency tree,
--debugcondition report, and direct DB table query; - JSON payload byte-for-byte diff: curl before and after, watch dates, nulls, defaults;
- Full test suite: compile errors for
@MockBean,@WebMvcTestwill surface here; - Global search for removed items: keywords like
undertow,pulsar; - Custom starters handled per version;
- Canary observation: startup time, jar size, key paths, memory usage;
- If automated tool used, review diff item by item.
What would make me advise not upgrading yet: you're still on Undertow / Spock / removed Spring Session integration with no alternative; a one-artifact custom starter costs too much to refactor; you have a pile of hand-newed ObjectMapper instances with uncontrollable downstream; or the Spring Cloud BOM you depend on hasn't supported Boot 4 yet.
Three things I'll remember from this upgrade
Version upgrades are an engineering problem, not a dependency management problem. What determines success is order - one variable at a time, full regression each step, and using behavior verification instead of compilation passing. Splitting JDK and Boot was, looking back, the most correct decision in the whole thing.
"Default switches" matter more than "new features". Compact Object Headers and generational Shenandoah are production features in 25 but not enabled by default; Jackson 3's date default changed; Flyway no longer auto-configures. The places that break are often not "what was added" but "what wasn't doing something".
Don't use second-hand articles as source of truth. In this verification I overturned three widely spread claims: Boot 4 requires Java 21, JEP 517 belongs to JDK 25, and structured concurrency became final in 25. Half an hour with official JEP pages and migration guides saves days of wrong debugging.
References
I mainly checked facts against these sources while writing:
- OpenJDK JDK 25 page, and the "JEPs integrated since JDK 21" list: openjdk.org/projects/jdk/25/
- OpenJDK JDK 26 page: openjdk.org/projects/jdk/26/
- JEP 506 / 519 / 521 detail pages
- Spring Boot 4.0 official migration guide (GitHub Wiki)
- Spring AI 2.0.0 and 2.1.0 official GA blog posts: spring.io/blog/
Top 2 from juejin.cn, machine-translated. The original thread is authoritative.
Upgrade JDK first, then Boot—the approach is solid.
Did you use an agent to assist with this work?