Spring Boot 4 Migration Guide
The Spring Boot 4 migration guide on this page walks you through upgrading an application from Spring Boot 3.x to 4.x. Spring Boot 4 is a major release: it is built on Spring Framework 7 and Jakarta EE 11, splits its auto-configuration into many small modules with matching starters, switches to Jackson 3 and removes everything deprecated in the 3.x line. Most applications upgrade in a day or two, as long as you follow a clear order and know where the breaking changes are.
This tutorial covers what to do before upgrading, the step-by-step path including the temporary "classic" starters, the starter and package renames, the Jackson 3 changes, removed features, changes to tests and behavior, and a checklist. Examples show the before and after for a typical order service.
1. What Changed in Spring Boot 4
| Area | Spring Boot 3.5 | Spring Boot 4 |
|---|---|---|
| Spring Framework | 6.2 | 7.x |
| Jakarta EE / Servlet | Jakarta EE 10 / Servlet 6.0 | Jakarta EE 11 / Servlet 6.1 |
| Minimum Java | 17 | 17 (the latest LTS, Java 25, is encouraged) |
| Auto-configuration | One large spring-boot-autoconfigure JAR | Small technology modules such as spring-boot-webmvc |
| JSON | Jackson 2 (com.fasterxml.jackson) | Jackson 3 (tools.jackson) |
| Embedded servers | Tomcat, Jetty, Undertow | Tomcat, Jetty |
| Null safety | Spring's own annotations | JSpecify annotations |
| Retry | Spring Retry project | Built into Spring Framework (@Retryable) |
| Mock beans in tests | @MockBean (deprecated) and @MockitoBean | @MockitoBean only |
The rest of the Spring portfolio moved too: Spring Security 7, Spring Data 2025.1, Spring for Apache Kafka 4, Spring AMQP 4, Spring Batch 6 and others. Read their release notes for the projects you use.
2. Before You Upgrade
- Upgrade to the latest 3.5.x release first and make sure the build and tests are green.
- Remove all deprecation warnings. Everything deprecated in 3.x is gone in 4.0, so a deprecated call today is a compile error tomorrow.
- Check third-party dependencies that Spring Boot does not manage, such as Spring Cloud or vendor SDKs, and find their versions for Spring Boot 4.
- Move to a supported Java version: at least 17, preferably 25. If you use GraalVM native images, version 25 or later is required.
- Make sure tests cover the important paths, including JSON serialization of your API responses, because Jackson 3 changes some defaults.
3. The Migration Path Step by Step
3.1 Use the Classic Starters as a Stepping Stone
Spring Boot 4 offers classic starters that put all of Spring Boot's modules on the classpath, much like Spring Boot 3. They let you fix compile errors first and worry about the new module layout second:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-classic</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test-classic</artifactId>
<scope>test</scope>
</dependency>
They replace spring-boot-starter and spring-boot-starter-test. Once the application works, remove them and add the specific starters your code needs; any missing starter then shows up as a missing class or bean.
3.2 Let the Properties Migrator Report Renamed Properties
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-properties-migrator</artifactId>
<scope>runtime</scope>
</dependency>
At startup it prints every renamed or removed property it finds and temporarily maps old names to new ones. Fix your configuration files from its report, then remove the dependency. OpenRewrite also provides automated recipes for many of these mechanical changes; review its changes like any other commit.
4. Modular Starters and Renamed Starters
Spring Boot 4 follows a strict naming convention: each technology has a module spring-boot-<technology> with root package org.springframework.boot.<technology>, a starter spring-boot-starter-<technology>, and a test starter spring-boot-starter-<technology>-test.
| Spring Boot 3 | Spring Boot 4 | Note |
|---|---|---|
spring-boot-starter-web | spring-boot-starter-webmvc | Old name deprecated |
spring-boot-starter-aop | spring-boot-starter-aspectj | Check whether you need it at all: only for @Aspect classes |
spring-boot-starter-oauth2-client | spring-boot-starter-security-oauth2-client | Same for resource server and authorization server |
spring-boot-starter-web-services | spring-boot-starter-webservices | Old name deprecated |
flyway-core or liquibase-core alone | spring-boot-starter-flyway / spring-boot-starter-liquibase | Technologies without a starter before now need one |
spring-boot-starter-test only | spring-boot-starter-webmvc-test, spring-boot-starter-data-jpa-test, ... | Each test starter includes spring-boot-starter-test |
RestTemplate / RestClient via the web starter | spring-boot-starter-restclient | Dedicated starter for HTTP clients |
WAR on external Tomcat: spring-boot-starter-tomcat (provided) | spring-boot-starter-tomcat-runtime | For WAR deployments |
The test starters matter more than they look: for example, Spring Security's @WithMockUser needs spring-boot-starter-security-test to work properly.
5. Package Moves That Break Imports
| Type | Spring Boot 3 package | Spring Boot 4 package |
|---|---|---|
@EntityScan | org.springframework.boot.autoconfigure.domain | org.springframework.boot.persistence.autoconfigure |
EnvironmentPostProcessor | org.springframework.boot.env | org.springframework.boot (old one deprecated) |
BootstrapRegistry and related | org.springframework.boot | org.springframework.boot.bootstrap |
@WebMvcTest, @AutoConfigureMockMvc | org.springframework.boot.test.autoconfigure.web.servlet | org.springframework.boot.webmvc.test.autoconfigure |
TestRestTemplate | org.springframework.boot.test.web.client | org.springframework.boot.resttestclient |
@PropertyMapping | org.springframework.boot.test.autoconfigure.properties | org.springframework.boot.test.context |
Other auto-configuration classes moved into their technology modules as well, for example org.springframework.boot.webmvc.autoconfigure. Your IDE's "organize imports" fixes most of these once the right starters are on the classpath. Spring Framework also deprecated a few names: HttpStatus.UNPROCESSABLE_ENTITY is now UNPROCESSABLE_CONTENT, and org.springframework.lang.Nullable gives way to JSpecify's org.jspecify.annotations.Nullable.
6. Upgrading to Jackson 3
Jackson 3 changed its Maven group IDs and Java packages from com.fasterxml.jackson to tools.jackson. The annotations module is the exception: @JsonProperty, @JsonIgnore and friends keep the com.fasterxml.jackson.annotation package, so most DTOs compile unchanged.
| Spring Boot 3 (Jackson 2) | Spring Boot 4 (Jackson 3) |
|---|---|
com.fasterxml.jackson.databind.ObjectMapper | tools.jackson.databind.json.JsonMapper (auto-configured) |
Defining an ObjectMapper bean replaces Boot's | Define a JsonMapper bean instead |
Jackson2ObjectMapperBuilderCustomizer | JsonMapperBuilderCustomizer |
@JsonComponent, @JsonMixin | @JacksonComponent, @JacksonMixin |
spring.jackson.read.* / spring.jackson.write.* | spring.jackson.json.read.* / spring.jackson.json.write.* |
| Only well-known modules registered | All Jackson modules on the classpath are registered |
If default serialization differences break clients, spring.jackson.use-jackson2-defaults=true makes the auto-configured mapper behave as closely as possible like Spring Boot 3. As a last resort, the deprecated spring-boot-jackson2 module keeps Jackson 2, configured under spring.jackson2.*; plan to remove it.
7. Test Changes
| Spring Boot 3 | Spring Boot 4 |
|---|---|
@MockBean / @SpyBean | @MockitoBean / @MockitoSpyBean (Spring Framework) |
@SpringBootTest provided MockMvc | Add @AutoConfigureMockMvc |
@SpringBootTest provided TestRestTemplate | Add @AutoConfigureTestRestTemplate, or use the new RestTestClient with @AutoConfigureRestTestClient |
@Mock / @Captor fields worked in Spring tests through a Boot listener | Use Mockito's MockitoExtension |
| Spock integration | Removed |
See Spring Boot testing and unit testing with JUnit and Mockito for the current style.
8. Removed Features
- Undertow: not compatible with Servlet 6.1; switch to Tomcat or Jetty.
- Fully executable JAR launch scripts: the embedded Unix launch script is gone; uber JARs still run with
java -jar. - The classic uber-JAR loader: remove
<loaderImplementation>CLASSIC</loaderImplementation>from your build. - Spring Retry dependency management: move to Spring Framework's
@Retryable, or declare a Spring Retry version yourself. - Spring Session Hazelcast and MongoDB support in Spring Boot (now maintained by those vendors), Pulsar Reactive auto-configuration and the Spock integration.
9. Behavior Changes to Review
| Change | What to check |
|---|---|
| Liveness and readiness probes enabled by default | /actuator/health now includes the probe groups; disable with management.endpoint.health.probes.enabled=false if unwanted |
| DevTools LiveReload disabled by default | Set spring.devtools.livereload.enabled=true if you use it |
| Optional Maven dependencies no longer packaged in uber JARs | Use <includeOptional>true</includeOptional> if needed |
| Logback files default to UTF-8 | Log shippers expecting another charset |
Spring Batch runs in-memory by default with spring-boot-starter-batch | Use spring-boot-starter-batch-jdbc to keep job metadata in your database |
| JSpecify nullability annotations | Kotlin code and null checkers may report new errors |
HttpMessageConverters deprecated | Use ServerHttpMessageConvertersCustomizer / ClientHttpMessageConvertersCustomizer |
10. A Complete Example: Upgrading an Order Service
10.1 Build File
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.5.16</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>4.2.0</version>
</parent>
<properties>
<java.version>25</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-flyway</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webmvc-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Spring Retry is gone because the service now uses Spring Framework's @Retryable, and the generic test starter was replaced by one test starter per technology. Depending on your database, add the Flyway database module (for example flyway-database-postgresql) as before.
10.2 Code
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
@WebMvcTest(OrderController.class)
class OrderControllerTest {
@MockBean
OrderService orders;
// ...
}
import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
@WebMvcTest(OrderController.class)
class OrderControllerTest {
@MockitoBean
OrderService orders;
// ...
}
package com.javabytechie.shop.config;
import org.springframework.boot.jackson.autoconfigure.JsonMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import tools.jackson.databind.SerializationFeature;
@Configuration
class JsonConfig {
// Spring Boot 3: Jackson2ObjectMapperBuilderCustomizer with com.fasterxml.jackson imports
@Bean
JsonMapperBuilderCustomizer orderJson() {
return builder -> builder.enable(SerializationFeature.INDENT_OUTPUT);
}
}
// Spring Boot 3: org.springframework.retry.annotation.Retryable with @EnableRetry
import org.springframework.resilience.annotation.Retryable;
@Retryable(includes = ResourceAccessException.class, maxRetries = 3, delay = 200, multiplier = 2)
public StockLevel stockFor(String sku) {
// ...
}
10.3 Configuration
# Spring Boot 3: spring.jackson.serialization.indent-output=true (still supported)
# Spring Boot 3: spring.jackson.read.* became spring.jackson.json.read.*
spring.jackson.json.read.allow-trailing-comma=true
Startup with the properties migrator still on the classpath lists any remaining renamed keys. When the build is green and the migrator reports nothing, remove it.
11. Migration Checklist
| # | Step | Done when |
|---|---|---|
| 1 | Upgrade to the latest 3.5.x and remove deprecations | No deprecation warnings in the build |
| 2 | Upgrade Java to 17+ (preferably 25) and third-party libraries | Compatible versions chosen for Spring Cloud and SDKs |
| 3 | Switch the parent to 4.x, add classic starters and the properties migrator | Project resolves dependencies |
| 4 | Fix imports, renamed starters and Jackson 3 code | Main code compiles |
| 5 | Replace @MockBean, add @AutoConfigureMockMvc where needed | Tests compile and pass |
| 6 | Fix properties reported by the migrator | Migrator reports nothing |
| 7 | Replace classic starters with technology starters and test starters | Build green without classic starters |
| 8 | Review behavior changes (probes, JSON output, batch metadata, Undertow) | Contract tests and smoke tests pass in a test environment |
| 9 | Remove the migrator, update documentation and dashboards | Ready for production rollout |
12. Best Practices
- Upgrade one major version at a time: latest 3.5.x first, then 4.0 or later.
- Separate the mechanical upgrade from feature work in its own branch and pull request.
- Use the classic starters only as a stepping stone, and remove them before release.
- Test JSON contracts explicitly, since Jackson 3 defaults differ from Jackson 2.
- Prefer the new APIs over compatibility switches such as
spring-boot-jackson2, which are deprecated. - Roll out gradually, for example one service or one canary instance first, and watch logs and metrics.
13. Summary
This Spring Boot 4 migration guide comes down to a clear order: get to the latest 3.5.x without deprecations, switch to the Spring Boot 4 parent with the classic starters and the properties migrator, fix imports, Jackson 3 code, tests and renamed properties, then move to the modular technology starters and their test starters. Watch for the removed features, notably Undertow, Spring Retry management and @MockBean, and review behavior changes such as health probes and batch metadata before going to production. Done step by step, the upgrade is mostly mechanical, and it brings Spring Framework 7, Jackson 3, built-in retries and leaner applications.
14. References
Spring Boot 4 Migration Guide Interview Questions and Answers
Common interview questions on Spring Boot 4 Migration Guide, from basic to scenario-based, with short answers you can explain in your own words.
Q. What are the biggest changes in Spring Boot 4 compared with Spring Boot 3?
Answer: It moves to Spring Framework 7 and Jakarta EE 11 (Servlet 6.1), splits auto-configuration into small technology modules with matching starters and test starters, switches to Jackson 3, adopts JSpecify null-safety annotations and removes everything deprecated in 3.x, including @MockBean and Undertow support. Retries and concurrency limits are now built into the framework.
Q. What are the classic starters, and when should you use them?
Answer: spring-boot-starter-classic and spring-boot-starter-test-classic put all Spring Boot modules on the classpath, recreating the Spring Boot 3 situation where every auto-configuration was available. They are a temporary aid: use them to get an upgraded application compiling and running, then replace them with the specific technology starters. The Spring team recommends moving away from them.
Q. After upgrading, Flyway migrations no longer run. Why?
Answer: In Spring Boot 4, technologies that previously needed only the third-party library now need their starter, because the auto-configuration lives in a separate module. With only flyway-core on the classpath, Flyway is no longer configured. Add spring-boot-starter-flyway (or spring-boot-starter-liquibase); the classic starters would also hide the problem temporarily.
Q. What changes for JSON handling with Jackson 3?
Answer: Packages and group IDs move from com.fasterxml.jackson to tools.jackson, except annotations, which stay put. Spring Boot auto-configures a JsonMapper, so overrides must define a JsonMapper bean; customizers become JsonMapperBuilderCustomizer; @JsonComponent becomes @JacksonComponent; and spring.jackson.read/write properties move under spring.jackson.json. spring.jackson.use-jackson2-defaults helps keep old output while you migrate.
Q. Which test changes usually break when upgrading to Spring Boot 4?
Answer: @MockBean and @SpyBean are removed in favor of @MockitoBean and @MockitoSpyBean; @SpringBootTest no longer sets up MockMvc or TestRestTemplate without @AutoConfigureMockMvc or @AutoConfigureTestRestTemplate; test annotations moved to technology packages; and missing test starters, such as spring-boot-starter-security-test, can make features like @WithMockUser stop working.
Q. Your team has 40 Spring Boot 3.3 services. How would you plan the upgrade to Spring Boot 4?
Answer: First bring every service to the latest 3.5.x and eliminate deprecations, ideally automated with OpenRewrite and shared through a common parent POM or BOM. Upgrade shared libraries and starters first, as separate Spring Boot 4 versions. Then migrate a pilot service end to end, document the issues, and roll out the rest in waves using the same recipe, classic starters as a stepping stone, contract tests for JSON, and canary deployments.