Quick revision
The short answer
Change one thing at a time. First move to the latest Spring Boot 2.7 and clear every deprecation warning; then move the JDK to 17 or 21 while still on Boot 2.7, upgrading build plugins, Lombok, Mockito and Java agents; then upgrade to Spring Boot 3.x, which needs Java 17 and renames javax.* to jakarta.*, using OpenRewrite for the mechanical part. Finish with full functional and performance tests, a check of GC and memory settings, and a gradual rollout with monitoring.
What to remember
In this answer, we saw that Boot 3 requires Java 17 and renames javax to jakarta, while Boot 2.7 already runs on newer JDKs, which lets us change one thing at a time. The order is latest 2.7 with deprecations cleared, then the JDK with plugins, Lombok, Mockito and agents upgraded, then Boot 3 with OpenRewrite doing the rename, and finally full and performance testing, a GC and memory check and a gradual rollout.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Change one thing at a time. First move to the latest Spring Boot 2.7 and clear every deprecation warning; then move the JDK to 17 or 21 while still on Boot 2.7, upgrading build plugins, Lombok, Mockito and Java agents; then upgrade to Spring Boot 3.x, which needs Java 17 and renames javax.* to jakarta.*, using OpenRewrite for the mechanical part. Finish with full functional and performance tests, a check of GC and memory settings, and a gradual rollout with monitoring.
Why this question is asked
Spring Boot 2.7 on Java 11 is a very common starting point, and both are long out of free support. The move to Boot 3 and Java 21 is worth doing, but trying it in one jump produces a pile of failures with no clear cause. Interviewers ask this to see whether we can sequence a migration so each step is small, testable and reversible. In this answer, we will recap why the two upgrades are linked, then walk through each stage in order, explaining what breaks at each one and why that order is safer than the alternatives.
1Why the JDK and Spring Boot Upgrades Are Tied Together
Spring Boot 3.0 made two big changes. It raised the minimum Java version to 17, because Spring Framework 6 uses Java 17 language features and APIs. And it moved from Java EE to Jakarta EE 9 and later, which renamed every enterprise package from javax.* to jakarta.*: javax.servlet became jakarta.servlet, javax.persistence became jakarta.persistence, javax.validation became jakarta.validation, and so on.
Spring Boot 2.7, on the other hand, runs on Java 8 up to Java 21 (check the documentation of the 2.7 patch release you use). That overlap is what makes a safe order possible: we can change the JDK while keeping Boot 2.7, and only then change Boot. If we did both at once and the service failed, we would not know whether the JDK, Boot, Hibernate, Spring Security or a library caused it.
- Latest Boot 2.7 patchclear deprecation warnings
- Java 17 or 21 on Boot 2.7upgrade plugins, Lombok, Mockito, agents
- Spring Boot 3.0, then latest 3.xjavax to jakarta with OpenRewrite
- Full tests and performance testscheck GC and memory settings
- Gradual rollout with monitoringcanary, then the rest
5 steps in order. Play them, or step through them one at a time.
Each step ships to production on its own before the next begins.
2Get to the Latest 2.7 and Clear Deprecations
We start by moving to the last 2.7 patch release, a small change that brings dependency upgrades and bug fixes. Then we turn on deprecation warnings in the compiler and fix every one that comes from Spring. The reason is simple: Spring Boot 3 removed most of what 2.x deprecated. A deprecated method that works today is a compile error tomorrow, so fixing it on 2.7 lets us test each fix in isolation.
Typical examples are the Spring Security changes: WebSecurityConfigurerAdapter is deprecated in 2.7 and gone in Security 6, so we rewrite the configuration as a SecurityFilterChain bean now. Spring's own advice is to move Spring Security to 5.8 while still on Boot 2.7, by overriding its version, because 5.8 already offers the 6.0 style such as requestMatchers and can be configured to behave like 6.0. We also add spring-boot-properties-migrator temporarily; at startup it reports configuration properties that were renamed or removed.
3Move the JDK While Staying on Boot 2.7
Now we change only the JDK, to 17 or straight to 21. Most of the work is in the build and the tooling around it, not in our code. Anything that reads or writes bytecode must understand the new class file version: the Maven or Gradle plugins, Lombok (an annotation processor that hooks deeply into javac, so old versions fail with odd compiler errors; for 21 we need 1.18.30 or later), Mockito and Byte Buddy (Mockito 5 is the safe choice on 21), JaCoCo, and Java agents for monitoring or profiling, which instrument bytecode at run time.
Code changes are usually small. Java 17 strongly encapsulates JDK internals, so libraries that used reflection on internal classes may fail with InaccessibleObjectException; the fix is to upgrade the library rather than add --add-opens flags. If we are coming from 11 we already handled the removed Java EE modules. We ship this step to production on its own, so any difference in behaviour can only come from the JDK.
4Upgrade to Spring Boot 3
With Java 17 or 21 in place, we move to Boot 3.0 first and then step up to the latest 3.x line, reading each release's migration notes. The rename from javax to jakarta is mechanical but touches hundreds of files, so we let a tool do it. OpenRewrite has recipes that update the Boot version, rename the packages, update properties and apply known API changes.
After the recipe we still review by hand, because Boot 3 brings behavioural changes no recipe can judge. Hibernate moves to version 6, which changes some query and type handling, so native queries and custom types need tests. Spring MVC no longer matches a trailing slash by default, so /orders/ and /orders are different paths. Spring Cloud Sleuth is replaced by Micrometer Tracing. Every library that uses javax types, such as an old servlet filter, must be upgraded to a Jakarta-compatible version, and the jdeps tool can help find them.
5Test Behaviour and Performance, Then Roll Out
Passing unit tests is not enough. We run the full integration and contract tests, and a load test that compares the old and new versions under the same traffic. Java 21 changes garbage collector defaults and heuristics compared with 11, and container awareness has improved, so we check heap sizing flags, GC logs, pause times and memory use. Old flags may now be ignored or fail at startup: the CMS collector was removed in Java 14, for example, so -XX:+UseConcMarkSweepGC no longer does anything useful.
This is also the moment to decide on new options, not to switch them on blindly. Virtual threads are available on Java 21 and Boot 3.2 and later through spring.threads.virtual.enabled=true, but they deserve their own change with their own measurements.
Finally we roll out gradually: one canary instance, then a percentage of traffic, then the rest, watching error rates, latency percentiles, GC and CPU. Because each previous step shipped separately, rolling back means going back one step, not three.
6Follow-up questions
Why not jump straight from Boot 2.7 on Java 11 to Boot 3 on Java 21?
Because three big changes at once, the JDK, the framework and the Jakarta rename, make every failure ambiguous. Splitting them means each production release has one cause of change, so a regression points at one step and rollback is cheap. The total effort is similar; the risk is much lower.
Should we pick Java 17 or 21 as the target?
Usually 21 or even 25, the newest LTS our tools support. The extra step from 17 to 21 costs little once plugins and agents are current, and it gives a longer support window and features such as virtual threads. We choose 17 only if a critical library or agent does not yet support 21.
What about Spring Boot 4?
Boot 4 builds on Spring Framework 7 and keeps the Java 17 baseline. Once on the latest 3.5, the step to 4 is a separate, smaller migration with its own release notes; we do not combine it with this one.
7Conclusion
In this answer, we saw that Boot 3 requires Java 17 and renames javax to jakarta, while Boot 2.7 already runs on newer JDKs, which lets us change one thing at a time. The order is latest 2.7 with deprecations cleared, then the JDK with plugins, Lombok, Mockito and agents upgraded, then Boot 3 with OpenRewrite doing the rename, and finally full and performance testing, a GC and memory check and a gradual rollout.
Open with
I would split it so that each production release changes one thing. First, move to the latest 2.7 patch and fix every deprecation warning, because Boot 3 removed most of them; for example I would replace WebSecurityConfigurerAdapter with a SecurityFilterChain bean, and add the properties migrator to catch renamed settings.
Then, if they want more
Second, change the JDK to 17 or 21 while still on Boot 2.7, which supports it. Most of that work is in tooling: build plugins, Lombok, Mockito and Byte Buddy, JaCoCo and any Java agents need versions that understand the new class files, and libraries that poke at JDK internals need upgrading.
Ship that. Third, upgrade to Spring Boot 3.0 and then the latest 3.x. Boot 3 needs Java 17 and moves from javax to jakarta, so I would run the OpenRewrite Spring Boot 3 recipe and then review Hibernate 6 behaviour, trailing slash matching, Micrometer Tracing and any third-party library still on javax.
Finally, run the full test suite plus a load test against the old version, check GC logs and memory flags because defaults changed since 11, and roll out with a canary and close monitoring.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 17, Java 21, Spring Boot 2.7, Spring Boot 3
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- The Java Language Specification, Java SE 21, Java SE 21 API documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Plan the upgrade of a Spring Boot 2.7 service on Java 11 to Java 21. What has to change...": https://scrivio-interview-library.netlify.app/java/java-versions/20663aceac/