All posts

Migration & platform 1. December 2026 7 min read

Spring Boot 4 Migration: A Guide with OpenRewrite and Coding Agents

The jump from 3 to 4 is smaller than the one from 2 to 3, but bigger than a version bump: the starters have been re-cut, Jackson 3 changes packages and classes, and a few test annotations are gone. What breaks, what OpenRewrite handles, and where a coding agent helps.

The short answer

A Spring Boot 4 migration starts on the latest 3.5.x: remove every deprecation warning first, then switch. The four big items are the re-cut starters, Jackson 3, removed test annotations such as @MockBean, and JSpecify null safety. OpenRewrite handles the mechanical renames, a coding agent handles the context-dependent rest in small, tested steps, and a human approves every merge.

Spring Boot 3.5 reached the end of its free support on 30 June 2026 (endoflife.date); the last free patch was 3.5.16. If you are still on 3.x, you no longer get community patches. That is no reason to panic, but it is a reason to plan the migration now rather than at the next CVE.

The good news: the jump from 3 to 4 is smaller than the one from 2 to 3. There is no javax → jakarta change that touches every class. The bad news: it is bigger than a version bump. The starters have been re-cut, Jackson 3 changes packages and classes, and a few test annotations are gone.

This guide shows what actually breaks, what OpenRewrite handles automatically, and where you can use a coding agent without giving up control.

The one rule up front: move to the latest 3.5.x first, get rid of every deprecation warning, and only then go to 4. What was deprecated in 3.x is removed in 4.0.

1. Check the prerequisites

Spring Boot 4 needs:

Component Minimum version
Java 17 (an LTS is recommended, 21 or 25)
Kotlin 2.2
GraalVM native-image 25
Jakarta EE / Servlet 11 / 6.1
Spring Framework 7.x

Two points that are often overlooked:

  • Undertow is out. The starter and the embedded support are gone because Undertow is not Servlet 6.1 compatible. If you use Undertow, switch to Tomcat or Jetty.
  • Dependencies outside of Boot. Spring Cloud and everything you pin yourself has to be moved to compatible versions by you. The Boot BOM does not help here.

2. Inventory: what does your application really use?

Before you change anything, make a list. It takes an hour and saves days:

mvn dependency:tree | grep -E "spring-boot-starter|jackson|undertow|spock"
grep -rE "@MockBean|@SpyBean|ObjectMapper|@JsonComponent|org.springframework.lang" src/

Write down:

  • Which starters (Web, Security, OAuth2, Flyway, Liquibase, Batch …)
  • Whether you have your own ObjectMapper beans or Jackson customizers
  • How many tests use @MockBean or @SpyBean
  • Which Spring projects are in there that Boot does not manage

This list is also the basis for any effort estimate.

3. What breaks: the big four

The complete list is in the official Spring Boot 4.0 Migration Guide. These four items cost the most time in practice.

Starters have been re-cut

Modules are now called spring-boot-<technology>, starters spring-boot-starter-<technology>. Some old names are deprecated:

Old New
spring-boot-starter-web spring-boot-starter-webmvc
spring-boot-starter-web-services spring-boot-starter-webservices
spring-boot-starter-oauth2-* spring-boot-starter-security-oauth2-*
spring-boot-starter-aop spring-boot-starter-aspectj

On top of that, Flyway and Liquibase now need their own starters (spring-boot-starter-flyway, spring-boot-starter-liquibase). If the starter is missing, the application starts, but your migrations do not run. This error is treacherous because it is not loud.

For the transition there are spring-boot-starter-classic and spring-boot-starter-test-classic. They bundle the auto-configuration as in 3.x. Good for getting the application running quickly, but not an end state.

Jackson 3

This is usually where a lot of the work sits:

  • Group IDs and packages move from com.fasterxml.jackson to tools.jackson. Exception: jackson-annotations stays.
  • @JsonComponent becomes @JacksonComponent, @JsonMixin becomes @JacksonMixin.
  • Jackson2ObjectMapperBuilderCustomizer becomes JsonMapperBuilderCustomizer.
  • Instead of an ObjectMapper bean you define a JsonMapper bean.
  • The properties spring.jackson.read.* and spring.jackson.write.* move to spring.jackson.json.*.

For the transition there are spring.jackson.use-jackson2-defaults and the deprecated module spring-boot-jackson2.

My advice: do not just get Jackson to compile, test it. Serialization likes to change silently: different defaults, different date formats, different null handling. A few snapshot tests on your most important API responses before the migration protect you against that.

Testing

  • @MockBean and @SpyBean are removed. Replacements: @MockitoBean and @MockitoSpyBean. They may no longer sit in @Configuration classes, though, but directly on the test class.
  • MockMvc explicitly needs @AutoConfigureMockMvc.
  • TestRestTemplate needs @AutoConfigureTestRestTemplate and the dependency spring-boot-resttestclient. Alternatively there is the new RestTestClient.
  • The Spock integration is gone because Spock does not yet support Groovy 5.

Null safety with JSpecify

Spring now relies on JSpecify annotations. You replace org.springframework.lang.Nullable and friends with org.jspecify.annotations.*. With null checkers or Kotlin this can surface new compile errors. That is annoying, but these errors are honest: they point at real gaps.

4. The mechanical part: OpenRewrite

For the tedious work there is a recipe that handles most of the renames:

mvn -U org.openrewrite.maven:rewrite-maven-plugin:run \
  -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-spring:RELEASE \
  -Drewrite.activeRecipes=org.openrewrite.java.spring.boot4.UpgradeSpringBoot_4_0 \
  -Drewrite.exportDatatables=true

Then read the git diff. Really read it. OpenRewrite is deterministic and traceable, but it does not know your application. It does not know that your frontend expects a particular date format or that a test uses a spy on purpose.

The properties migrator also helps you find renamed properties at runtime:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-properties-migrator</artifactId>
  <scope>runtime</scope>
</dependency>

Remove it again after the migration.

5. The rest: a coding agent with guardrails

After OpenRewrite, what typically remains is what a recipe cannot do: rebuilding custom Jackson serializers, restructuring test configurations, resolving compile errors from JSpecify, replacing deprecated starters with the right modules.

That is good work for a coding agent, on three conditions:

  1. Small steps, one commit per kind of change. Not "migrate everything", but "replace all @MockBean in the billing module". That keeps every diff reviewable.
  2. Tests as the referee. The agent may only complete a step when the test suite is green. Without tests, an agent in a migration is a risk, not a tool. How to build a safety net is covered in the guide to rescuing an AI-generated codebase.
  3. A human merges. The agent proposes, you decide. For reviewing the diffs, the 12-point checklist for AI-generated code helps.

The division of labour that has proven itself: OpenRewrite for the deterministic part, the agent for the context-dependent part, the human for the approval.

6. An order that works

  1. Move to the latest 3.5.x, deprecation warnings down to zero
  2. Add snapshot tests for critical JSON responses
  3. Inventory (section 2)
  4. Spring Boot 4 with the classic starters: the application starts, the core flows work
  5. OpenRewrite recipe, review the diff
  6. Remaining errors step by step, with an agent or by hand
  7. Replace the classic starters with the technology-specific ones
  8. Remove the properties migrator, release

Keep steps 4 and 7 deliberately apart. Stable first, then clean.

7. Checklist: the silent errors

All of this compiles and only shows up in production:

  • Flyway/Liquibase starter present? Do the migrations run at startup?
  • JSON responses identical to before (snapshot tests)?
  • Liveness and readiness probes are now enabled by default. Does that fit your Kubernetes configuration?
  • Logback now writes files in UTF-8 by default. Does a log parser expect something else?
  • Maven: optional dependencies no longer end up in the uber jar. Is something missing at runtime?
  • Spring Batch works in memory with the default starter. For metadata in the database you need spring-boot-starter-batch-jdbc.
  • Spring Session properties renamed (spring.session.redis.* → spring.session.data.redis.*)?

Conclusion

The Spring Boot 4 migration is not an adventure, but it is not an afternoon task either. The effort is rarely in the framework itself; it is in Jackson, in the tests and in everything that silently behaves differently. If you clean up on 3.5 first, add snapshot tests and use OpenRewrite for the mechanical part, you have most of the risk under control.

The one thing you can do today: run the inventory from section 2 and count the hits. The number tells you whether you are talking about days or weeks.


Don't want to do the migration alone? We run a migration assessment for your codebase: inventory, risks, plan. After that you decide whether you migrate yourselves or with us. The service page is available in German and French, or write to hire@halvic.ch.

Frequently asked questions

Do I have to upgrade to Spring Boot 3.5 before migrating to Spring Boot 4?

Yes. Move to the latest 3.5.x first and remove all deprecation warnings. What was deprecated in 3.x is removed in 4.0. If you skip this step, you hunt the same errors later in a much larger diff.

What breaks most often when migrating from Spring Boot 3 to 4?

Four areas: the re-cut starters (for example spring-boot-starter-webmvc instead of spring-boot-starter-web, dedicated starters for Flyway and Liquibase), Jackson 3 with new packages and classes, testing (@MockBean and @SpyBean are removed, MockMvc needs @AutoConfigureMockMvc) and null safety with JSpecify.

Can OpenRewrite do the Spring Boot 4 migration automatically?

The mechanical part. The UpgradeSpringBoot_4_0 recipe handles most of the renames. It does not know your application, though: custom Jackson serializers, test configurations and compile errors from JSpecify are left over. Read the whole diff after the run.

Which errors only show up in production after the migration?

The silent ones: a missing Flyway or Liquibase starter (the application starts, the migrations do not run), JSON responses changed by Jackson 3, liveness and readiness probes that are now on by default, log files in UTF-8, optional dependencies missing from the uber jar, and Spring Batch running in memory with the default starter.