Spring Framework 6.2
When upgrading to Spring Framework 6.2, refer to the Spring Framework 6.2 Release Notes for newly introduced APIs, deprecated APIs, and breaking changes.
The io.arconia.rewrite.spring.framework6.UpgradeSpringFramework_6_2 recipe automates most of the changes introduced in Spring Framework 6.2. You can use it to update your project to the latest Spring Framework 6.2.x release.
The recipe will:
-
Upgrade all
org.springframeworkdependencies to the 6.2.x release line. -
Swap the deprecated
org.webjars:webjars-locator-coreartifact fororg.webjars:webjars-locator-lite. -
For Spring Beans: rename
BeanInstanceSupplier.withShortcuts(…)towithShortcut(…). -
For Spring Context: rename
MethodValidationResult.getAllValidationResults()togetParameterValidationResults(). -
For Spring Messaging: rename the async APIs to their
*Async/CompletableFuture-based forms, includingAsyncHandlerMethodReturnValueHandler.toListenableFuture(…)→toCompletableFuture(…),ConnectionHandlingStompSession.getSessionFuture()→getSession(),ReactorNettyTcpStompClient.connect(…)→connectAsync(…), and theTcpConnection.send(…),TcpOperations.connect(…), andTcpOperations.shutdown()renames tosendAsync,connectAsync, andshutdownAsync. -
For Spring Test:
-
Rename
ExchangeResult.getRawStatusCode()togetStatus(). -
Rename
WebTestClient.RequestBodySpec.syncBody(…)tobodyValue(…). -
Rename the
StatusResultMatchersmatchers:isMovedTemporarily()→isFound(),isRequestEntityTooLarge()→isPayloadTooLarge(),isRequestUriTooLong()→isUriTooLong(), andisCheckpoint()→isEarlyHints().
-
-
For Spring Web:
-
Replace
getStatusCodeValue()withgetStatusCode()onResponseEntity, andgetRawStatusCode()withgetStatusCode()onClientHttpResponse(servlet and reactive),ServerHttpResponse,RestClientResponseException, andUnknownContentTypeException. -
Rename
getResponseHeaders()togetHeaders()onMethodNotAllowedException,NotAcceptableStatusException,ResponseStatusException, andUnsupportedMediaTypeStatusException; renameResponseStatusExceptionHandler.determineRawStatusCode(…)todetermineStatus(…). -
Rename
UriComponentsBuilder.fromHttpUrl(String)andfromOriginHeader(…)tofromUriString(…). -
Replace deprecated
MediaTypeconstants:APPLICATION_GRAPHQL/_VALUE→APPLICATION_GRAPHQL_RESPONSE/_VALUE,APPLICATION_JSON_UTF8/_VALUE→APPLICATION_JSON/_VALUE,APPLICATION_PROBLEM_JSON_UTF8/_VALUE→APPLICATION_PROBLEM_JSON/_VALUE, andAPPLICATION_STREAM_JSON/_VALUE→APPLICATION_NDJSON/_VALUE. -
Replace deprecated
HttpStatusconstants:MOVED_TEMPORARILY→FOUND,REQUEST_ENTITY_TOO_LARGE→PAYLOAD_TOO_LARGE, andREQUEST_URI_TOO_LONG→URI_TOO_LONG.
-
-
For Spring WebFlux:
-
Rename
BodyInserters.fromObject(…)tofromValue(…)andClientRequest.method(…)tocreate(…). -
Rename
rawStatusCode()tostatusCode()onClientResponseandServerResponse, andWebClientResponseException.getRawStatusCode()togetStatusCode(). -
Rename
WebClient.Builder.exchangeStrategies(…)tocodecs(…),WebClient.RequestBodySpec.syncBody(…)tobodyValue(…), andServerResponse.BodyBuilder.syncBody(…)tobodyValue(…). -
Rename
ServerRequest.methodName()tomethod()andServerRequest.pathContainer()torequestPath(). -
Consolidate the
ReactorNettyWebSocketClient.getHandlePing()/getMaxFramePayloadLength()getters intogetWebsocketClientSpec()and the equivalentReactorNettyRequestUpgradeStrategygetters intogetWebsocketServerSpec().
-
-
For Spring WebMVC:
-
Rename
ServerRequest.methodName()tomethod(),ServerRequest.pathContainer()torequestPath(), andServerResponse.rawStatusCode()tostatusCode(). -
Rename
AbstractHandlerMethodMapping.getMappingPathPatterns(…)togetDirectPaths(…)andMappedInterceptor.getPathPatterns()togetIncludePathPatterns(). -
Replace the
CookieLocaleResolver/SessionLocaleResolverdetermineDefaultLocale(…)/determineDefaultTimeZone(…)methods with the newsetDefaultLocaleFunction(…)/setDefaultTimeZoneFunction(…)setters.
-
-
For Spring WebSocket:
-
Rename
AbstractWebSocketClient.doHandshakeInternal(…)toexecuteInternal(…)andWebSocketClient.doHandshake(…)toexecute(…). -
Drop the
Infosuffix fromWebSocketMessageBrokerStats.getWebSocketSessionStatsInfo(),getStompSubProtocolStatsInfo(), andgetStompBrokerRelayStatsInfo(). -
Rename
WebSocketStompClient.connect(…)andTransport.connect(…)toconnectAsync(…).
-
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.framework6.UpgradeSpringFramework_6_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.framework6.UpgradeSpringFramework_6_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.framework6.UpgradeSpringFramework_6_2