Spring Boot 4.0
When upgrading to Spring Boot 4.0, refer to the Spring Boot 4.0 Release Notes and Spring Boot 4.0 Migration Guide to find out about newly introduced APIs, deprecated APIs, and information about breaking changes.
The io.arconia.rewrite.spring.boot4.UpgradeSpringBoot_4_0 recipe automates most of the changes introduced in Spring Boot 4.0. It also chains the Spring Boot 3.5 upgrade recipe, so you can apply it to projects still on earlier 3.x lines.
The recipe will:
-
Apply the full Spring Boot 3.5 upgrade as a prerequisite.
-
Upgrade all
org.springframework.bootdependencies, thespring-boot-starter-parentMaven parent, and the Spring Boot Gradle and Maven plugins to the 4.0.x release line. -
Rename Spring Boot configuration properties to match the new property names.
-
Apply the changes required by the Spring Boot 4.0 modularization effort across the Spring Boot codebase. Most of the code that used to live in a single auto-configuration module has been relocated into many focused modules and packages, with some types renamed in the process. The recipe takes care of the resulting dependency, package, and type updates so your project keeps compiling after the upgrade. See the Spring Boot 4.0 Migration Guide for the rationale and the full list of affected modules.
-
Upgrade Spring Framework to 7.0, which itself pulls in Jackson 3 and JUnit 6.
-
Chain the Testcontainers 2, Spring Cloud 2025.1, and Spring AI 2.0 upgrade recipes, since their managed versions move with Spring Boot.
-
Upgrade related build plugins (GraalVM Native Build Tools to 0.11.x, CycloneDX SBOM to 3.x) and adjacent libraries (SpringDoc to 3.0.x, JobRunr to 8.x with the new
jobrunr-spring-boot-4-starterartifact). -
Apply breaking changes for the testing setup: add the
@AutoConfigureRestTestClient,@AutoConfigureTestRestTemplate, and@AutoConfigureWebTestClientannotations where they’re now required.
Run the recipe
You can apply this recipe with any OpenRewrite-compatible tool. The tabs below show three of them: the Arconia CLI, the OpenRewrite Gradle plugin, and the OpenRewrite Maven plugin. See Running Recipes for a comparison of when to pick each one.
-
Arconia CLI
-
Gradle
-
Maven
arconia update spring-boot --to-version=4.0
First, create an init.gradle file in your project root with the following content.
initscript {
repositories {
maven { url "https://plugins.gradle.org/m2" }
}
dependencies {
classpath("org.openrewrite:plugin:latest.release")
}
}
rootProject {
plugins.apply(org.openrewrite.gradle.RewritePlugin)
dependencies {
rewrite("io.arconia.migrations:rewrite-spring:latest.release")
}
afterEvaluate {
if (repositories.isEmpty()) {
repositories {
mavenCentral()
}
}
}
configurations.named("rewrite") {
canBeConsumed = false
}
}
Then, run the following command.
./gradlew rewriteRun \
--init-script init.gradle \
-DactiveRecipe=io.arconia.rewrite.spring.boot4.UpgradeSpringBoot_4_0
You can remove the init.gradle file afterwards.
./mvnw -U org.openrewrite.maven:rewrite-maven-plugin:run \
-Drewrite.recipeArtifactCoordinates=io.arconia.migrations:rewrite-spring:LATEST \
-Drewrite.activeRecipes=io.arconia.rewrite.spring.boot4.UpgradeSpringBoot_4_0