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.springframework dependencies to the 6.2.x release line.

  • Swap the deprecated org.webjars:webjars-locator-core artifact for org.webjars:webjars-locator-lite.

  • For Spring Beans: rename BeanInstanceSupplier.withShortcuts(…​) to withShortcut(…​).

  • For Spring Context: rename MethodValidationResult.getAllValidationResults() to getParameterValidationResults().

  • For Spring Messaging: rename the async APIs to their *Async / CompletableFuture-based forms, including AsyncHandlerMethodReturnValueHandler.toListenableFuture(…​)toCompletableFuture(…​), ConnectionHandlingStompSession.getSessionFuture()getSession(), ReactorNettyTcpStompClient.connect(…​)connectAsync(…​), and the TcpConnection.send(…​), TcpOperations.connect(…​), and TcpOperations.shutdown() renames to sendAsync, connectAsync, and shutdownAsync.

  • For Spring Test:

    • Rename ExchangeResult.getRawStatusCode() to getStatus().

    • Rename WebTestClient.RequestBodySpec.syncBody(…​) to bodyValue(…​).

    • Rename the StatusResultMatchers matchers: isMovedTemporarily()isFound(), isRequestEntityTooLarge()isPayloadTooLarge(), isRequestUriTooLong()isUriTooLong(), and isCheckpoint()isEarlyHints().

  • For Spring Web:

    • Replace getStatusCodeValue() with getStatusCode() on ResponseEntity, and getRawStatusCode() with getStatusCode() on ClientHttpResponse (servlet and reactive), ServerHttpResponse, RestClientResponseException, and UnknownContentTypeException.

    • Rename getResponseHeaders() to getHeaders() on MethodNotAllowedException, NotAcceptableStatusException, ResponseStatusException, and UnsupportedMediaTypeStatusException; rename ResponseStatusExceptionHandler.determineRawStatusCode(…​) to determineStatus(…​).

    • Rename UriComponentsBuilder.fromHttpUrl(String) and fromOriginHeader(…​) to fromUriString(…​).

    • Replace deprecated MediaType constants: APPLICATION_GRAPHQL / _VALUEAPPLICATION_GRAPHQL_RESPONSE / _VALUE, APPLICATION_JSON_UTF8 / _VALUEAPPLICATION_JSON / _VALUE, APPLICATION_PROBLEM_JSON_UTF8 / _VALUEAPPLICATION_PROBLEM_JSON / _VALUE, and APPLICATION_STREAM_JSON / _VALUEAPPLICATION_NDJSON / _VALUE.

    • Replace deprecated HttpStatus constants: MOVED_TEMPORARILYFOUND, REQUEST_ENTITY_TOO_LARGEPAYLOAD_TOO_LARGE, and REQUEST_URI_TOO_LONGURI_TOO_LONG.

  • For Spring WebFlux:

    • Rename BodyInserters.fromObject(…​) to fromValue(…​) and ClientRequest.method(…​) to create(…​).

    • Rename rawStatusCode() to statusCode() on ClientResponse and ServerResponse, and WebClientResponseException.getRawStatusCode() to getStatusCode().

    • Rename WebClient.Builder.exchangeStrategies(…​) to codecs(…​), WebClient.RequestBodySpec.syncBody(…​) to bodyValue(…​), and ServerResponse.BodyBuilder.syncBody(…​) to bodyValue(…​).

    • Rename ServerRequest.methodName() to method() and ServerRequest.pathContainer() to requestPath().

    • Consolidate the ReactorNettyWebSocketClient.getHandlePing() / getMaxFramePayloadLength() getters into getWebsocketClientSpec() and the equivalent ReactorNettyRequestUpgradeStrategy getters into getWebsocketServerSpec().

  • For Spring WebMVC:

    • Rename ServerRequest.methodName() to method(), ServerRequest.pathContainer() to requestPath(), and ServerResponse.rawStatusCode() to statusCode().

    • Rename AbstractHandlerMethodMapping.getMappingPathPatterns(…​) to getDirectPaths(…​) and MappedInterceptor.getPathPatterns() to getIncludePathPatterns().

    • Replace the CookieLocaleResolver / SessionLocaleResolver determineDefaultLocale(…​) / determineDefaultTimeZone(…​) methods with the new setDefaultLocaleFunction(…​) / setDefaultTimeZoneFunction(…​) setters.

  • For Spring WebSocket:

    • Rename AbstractWebSocketClient.doHandshakeInternal(…​) to executeInternal(…​) and WebSocketClient.doHandshake(…​) to execute(…​).

    • Drop the Info suffix from WebSocketMessageBrokerStats.getWebSocketSessionStatsInfo(), getStompSubProtocolStatsInfo(), and getStompBrokerRelayStatsInfo().

    • Rename WebSocketStompClient.connect(…​) and Transport.connect(…​) to connectAsync(…​).

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