Spring Framework 7.0
When upgrading to Spring Framework 7.0, refer to the Spring Framework 7.0 Release Notes for newly introduced APIs, deprecated APIs, and breaking changes.
The io.arconia.rewrite.spring.framework7.UpgradeSpringFramework_7_0 recipe automates most of the changes introduced in Spring Framework 7.0. You can use it to update your project to the latest Spring Framework 7.0.x release.
The recipe will:
-
Upgrade all
org.springframeworkdependencies to the 7.0.x release line. -
Apply the related upgrades to Jackson 3 and JUnit 6, which are required for compatibility with Spring Framework 7.0.
-
For Spring Core:
-
Migrate nullness annotations from
org.springframework.lang.{NonNull,Nullable}to the JSpecify package (org.jspecify.annotations.{NonNull,Nullable}). -
Rename
FilePatternResourceHintsRegistrar.Builder.withClasspathLocations(…)towithClassPathLocations(…). -
Replace the
MemberCategory.DECLARED_FIELDSandMemberCategory.PUBLIC_FIELDSconstants withINVOKE_DECLARED_FIELDSandINVOKE_PUBLIC_FIELDS.
-
-
For Spring Test: rename
StatusResultMatchers.isPayloadTooLarge()toisContentTooLarge()andisUnprocessableEntity()toisUnprocessableContent(), aligning with the HTTP status name updates in RFC 9110. -
For Spring Web:
-
Switch
Jackson2ObjectMapperBuilderfor the new Jackson 3tools.jackson.databind.json.JsonMapper.Builder. -
Rename
PayloadTooLargeExceptiontoContentTooLargeException. -
Rename
ResponseEntity.unprocessableEntity()tounprocessableContent(). -
Replace the
HttpStatus.PAYLOAD_TOO_LARGEandHttpStatus.UNPROCESSABLE_ENTITYconstants withCONTENT_TOO_LARGEandUNPROCESSABLE_CONTENT.
-
-
For Spring WebFlux:
-
Rename
ServerResponse.unprocessableEntity()tounprocessableContent(). -
Rename the
WebClientResponseException.UnprocessableEntitynested type toUnprocessableContent. -
Rename the
FragmentsRenderingbuilder methods:with(…)→fragment(…),withCollection(…)→fragments(…),withPublisher(…)→fragmentsPublisher(…), andwithProducer(…)→fragmentsProducer(…).
-
-
For Spring WebMVC:
-
Rename
ServerResponse.unprocessableEntity()tounprocessableContent(). -
Rename the
FragmentsRenderingbuilder methods:with(String)andwith(String, Map)tofragment(…), andwith(Collection)tofragments(…). -
Rename the lowercase
RequestContext.jstlPresentconstant to the uppercaseJSTL_PRESENT.
-
-
Migrate Spring Retry to the retry support built into Spring Framework, which succeeds it:
-
Replace
@EnableRetrywith@EnableResilientMethods. -
Replace the Spring Retry
@Retryablewith the Spring Framework one, carrying over the exception types (retryForandnoRetryForbecomeincludesandexcludes) and the backoff (the@Backoffdelay, multiplier, and maximum delay become attributes of@Retryable). Spring Retry counts the initial invocation inmaxAttempts, while Spring Framework counts only the retries inmaxRetries, somaxAttempts = 5becomesmaxRetries = 4, and an annotation withoutmaxAttemptsgetsmaxRetries = 2to keep the Spring Retry default of three attempts. An exponential backoff without a greatermaxDelaygetsmaxDelay = 30000, the cap Spring Retry applied implicitly. -
Remove the Spring Retry dependency, unless the project uses Spring Cloud. Several Spring Cloud features switch on when Spring Retry is on the classpath, such as load-balanced
RestTemplate,RestClient, and OpenFeign client retry, and Config Client (up to Spring Cloud 2025.1), Consul, and Kubernetes config retry, and would silently stop retrying without it.
-
The Spring Retry migration changes a project only when every Spring Retry usage in it has a Spring Framework equivalent, and otherwise leaves the project unchanged, so it is never left half migrated. In a multi-module build, each module is checked on its own. A project that uses RetryTemplate or any other Spring Retry API, @Recover or @CircuitBreaker, stateful retry, listeners, a custom interceptor, SpEL expressions, a random or uniform random backoff, or retries a method with a reactive return type is left unchanged, and needs to be migrated manually. Spring Framework retries a reactive method by resubscribing to it, while Spring Retry only retried the method call itself. Unlike @EnableRetry, @EnableResilientMethods does not enable AspectJ auto-proxying, which Spring Boot enables on its own. The Spring Retry migration is also available on its own as the MigrateSpringRetryToSpringFramework recipe.
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 rewrite run --recipe-name io.arconia.rewrite.spring.framework7.UpgradeSpringFramework_7_0
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.framework7.UpgradeSpringFramework_7_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.framework7.UpgradeSpringFramework_7_0