Spring Boot 4.2
When upgrading to Spring Boot 4.2, refer to the Spring Boot 4.2 Release Notes for newly introduced APIs, deprecated APIs, and breaking changes.
The io.arconia.rewrite.spring.boot4.UpgradeSpringBoot_4_2 recipe automates most of the changes introduced in Spring Boot 4.2. It also chains the Spring Boot 4.1 upgrade recipe, so you can apply it to projects that are still on earlier 4.x or 3.x lines.
The recipe will:
-
Apply the full Spring Boot 4.1 upgrade as a prerequisite (which itself chains Spring Boot 4.0 and 3.5).
-
Upgrade all
org.springframework.bootdependencies, thespring-boot-starter-parentMaven parent, and the Spring Boot Gradle and Maven plugins to the 4.2.x release line. -
Rename Spring Boot configuration properties that changed, such as the servlet-specific Tomcat properties that moved beneath
server.tomcat.servlet, and comment out those removed so you can address them manually. -
Upgrade Spring Framework to 7.1.
-
Chain the Spring Cloud 2026.0 and Spring AI 2.1 upgrade recipes, since their managed versions move with Spring Boot.
-
Chain the Spring Modulith 2.2, Spring Security 7.2, and Spring Data 2026.1 upgrade recipes, since their managed versions move with Spring Boot. The event publication properties whose deprecated spellings are removed in Spring Modulith 2.2 are renamed by the chained Spring Boot 4.0 and 4.1 upgrades.
-
Keep the application on AMQP 0.9 by moving from the
spring-boot-starter-amqpstarter and thespring-boot-amqpmodule, which now provide AMQP 1.0 support, to thespring-boot-starter-rabbitmqstarter and thespring-boot-rabbitmqmodule, including their test starters and theorg.springframework.boot.rabbitmqpackages. Configuration properties underspring.rabbitmqare unchanged. Adopting AMQP 1.0 instead means migrating to thespring-boot-starter-amqp-rabbitmqstarter and its new template and listener APIs, which is a manual migration. -
Replace the
HttpMessageConvertersclass removed from the Spring Boot HTTP Converter module with the Spring Framework interface of the same name. Both are iterable over the configured converters, so injection points and loops keep working. Code that constructed the removed class needs to be reworked manually around theHttpMessageConverters.forServer()andforClient()builders.
Some changes in Spring Boot 4.2 are deliberately not automated. RestTemplateBuilder, TestRestTemplate, and their supporting types are deprecated in favor of RestClient and RestTestClient, but still work, and moving to the new clients is a code change you should make on your own terms. The KafkaProperties methods that build client configuration are deprecated in favor of KafkaConfigBuilder. Several defaults also changed, such as Tomcat now using relative redirects and spring.test.database.replace defaulting to non-test, so review the release notes for behavior changes that may affect your application.
See its entry in the Recipe Catalog for the full list of recipes this upgrade applies, each with its options and a before/after example.
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.2
First, create an init.gradle file in your project root with the following content.
initscript {
repositories {
gradlePluginPortal()
}
dependencies {
classpath("org.openrewrite:plugin:latest.release")
}
}
rootProject {
plugins.apply(org.openrewrite.gradle.RewritePlugin)
dependencies {
rewrite("io.arconia.migrations:rewrite-spring:latest.release")
}
// Remove when project repositories are disabled
afterEvaluate {
if (repositories.isEmpty()) {
repositories {
mavenCentral()
}
}
}
configurations.named("rewrite") {
canBeConsumed = false
}
}
Then, run the following command.
./gradlew rewriteRun \
--init-script init.gradle \
--no-parallel \
-DactiveRecipe=io.arconia.rewrite.spring.boot4.UpgradeSpringBoot_4_2
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_2