Spring Framework 7.1 deprecates RestTemplate and lists Framework 8.0 as the removal target. Its synchronous successor, RestClient, has been available since Framework 6.1. If you're already on a version that supports it, you can move one client at a time and handle the framework upgrade separately. Framework deprecations · Framework 6.1 announcement
The tricky part is preserving what the rest of your application sees. Take a shop that asks a shipping partner whether it can deliver to an address. For this API, a 404 means the partner doesn't serve that address. A 503 means the shop can't check right now. If the new client turns an empty 503 response into an empty result, checkout tells the customer that delivery is unavailable. The code compiles, and the shop gives the wrong answer.
Start with one integration. Write down what should happen when the call succeeds, when the partner returns an error and when the call times out. Then run the same checks on both clients. Our earlier guide applies the same idea to framework updates. Spring Patch Thursday
What changed in Spring?
Spring Framework 7.1.0 and Spring Boot 4.2.0 were both released on November 19, 2026. The Framework deprecation covers RestTemplate itself. Boot 4.2 also deprecates its RestTemplateBuilder, RestTemplateCustomizer and TestRestTemplate, with Boot 4.4.0 as the removal target. Look for these separately when you inventory your code. Application client configuration can move to RestClient.Builder and RestClientCustomizer. Review your server endpoint tests separately if they use TestRestTemplate. Framework release · Boot release · Boot deprecations
Check which Framework version your build resolves. Boot 3.2 already used Framework 6.1. If you're on Framework 6.0 or earlier, first upgrade to a compatible managed dependency set that includes RestClient. The lab below runs with Framework 7.1.0 and Java 21, without Boot. Boot 3.2 requirements
Agree on what the caller should see
List the systems your client calls and note who relies on each result. Start the tests with the old client, while you have its behavior in front of you. In the lab, checkout calls one method, ShippingOptions.find(destination, postcode). The table shows what that method should return or throw for the shipping API. More on testing an API contract from the consumer's side
| Partner response | Outcome for the checkout |
|---|---|
| 200 with an option in JSON | Return the shipping option |
| Contractual 404, with or without an error body | No shipping option |
| 503, with or without an error body | Partner temporarily unavailable |
| Empty 200 or 204 | Partner protocol failure |
| Read timeout before response headers | Transport failure |
Only the contractual 404 returns Optional.empty(). The tests use both HTML and empty error bodies to check that the outcome comes from the status. If your API puts a business error code in the body, give its decoder a size limit and decide what to do when the body is missing or malformed.
Make the same call with RestClient
The RestTemplate adapter sends a GET and lets its ResponseErrorHandler map error statuses before the success body is decoded.
var headers = new HttpHeaders();
headers.setAccept(List.of(MediaType.APPLICATION_JSON));
var response = template.exchange(LOOKUP, HttpMethod.GET,
new HttpEntity<Void>(headers), Option.class, destination, postcode);
return ShippingContract.requireOption(response.getStatusCode().value(), response.getBody());
With RestClient, retrieve().toEntity(...) gives you the same response shape, with access to status and body. Both adapters turn the internal 404 signal into an empty result and wrap a ResourceAccessException as a transport failure. A 503 still raises PartnerUnavailable.
var response = client.get()
.uri(LOOKUP, destination, postcode)
.accept(MediaType.APPLICATION_JSON)
.retrieve()
.toEntity(Option.class);
return ShippingContract.requireOption(response.getStatusCode().value(), response.getBody());
Check what actually goes over the wire. Both clients use the same base path, URI template and encoding mode. The test server checks the raw target, including a slash inside the destination and a literal plus in the query. It expects Accept: application/json and a bodyless GET. For calls that send a body, also check Content-Type and how your converters serialize representative fields. Spring URI building
Take the existing configuration with you
RestClient.create(existingRestTemplate) is a useful first step. Use builder(existingRestTemplate) if you need to adjust settings before building. The bridge carries over the request factory, converters, interceptors, initializers, compatible URI builder and error handler. Spring 7.1.0 also copies buffering and observation settings. Check your URLs even when you use the bridge. Spring skips the uncustomized legacy URI defaults and handlers that only implement UriTemplateHandler. The lab runs both bridge paths. RestClient Javadoc · Tagged builder implementation
You can also pass the old handler explicitly with builder.defaultStatusHandler(existingHandler). Framework 7.1 deprecates this overload too, so use it during the transition. The independent client in the lab uses a status predicate and a callback. RestClient.Builder Javadoc
.defaultStatusHandler(status -> ShippingContract.requiresStatusMapping(status.value()),
(request, response) ->
ShippingContract.checkStatus(response.getStatusCode().value()))
With retrieve(), a matching request-level onStatus handler comes first. Then Spring checks the builder's handlers in registration order and falls back to its default error handling. A handler that returns normally can let decoding continue. In the lab, the handler throws for 404 and 503 before a success converter sees the error body. REST clients reference · ResponseSpec Javadoc
The trap in switching to exchange()
Both clients have an exchange() method, and the name can make the migration look straightforward. RestTemplate.exchange() runs the old error handler. RestClient.exchange() hands the response directly to your callback. The callback below decodes a successful response, but it also turns an empty 503 into Optional.empty(). That's how a partner outage becomes a “no delivery option” message.
return (destination, postcode) -> client.get()
.uri(LOOKUP, destination, postcode)
.accept(MediaType.APPLICATION_JSON)
.exchange((request, response) ->
Optional.ofNullable(response.bodyTo(ShippingOptions.Option.class)));
The test below checks what checkout sees. With the broken adapter, JUnit reports that no exception was thrown. Change the error body and the same bug looks different. HTML fails conversion, while JSON that happens to fit the success type can even come back as a shipping option.
var failure = assertThrows(ShippingOptions.PartnerUnavailable.class, () -> find(client));
assertEquals("Shipping partner temporarily unavailable", failure.getMessage());
assertNull(failure.getCause());
If you need exchange() for custom response handling, inspect the status first and decode the body while the callback still owns the response. This example uses Spring 7.1's response API. The full adapter in the lab preserves the same 404 and transport behavior. RequestHeadersSpec Javadoc
.exchange((request, response) -> {
int status = response.getStatusCode().value();
ShippingContract.checkStatus(status);
return ShippingContract.requireOption(status,
response.bodyTo(ShippingOptions.Option.class));
});
Keep the same transport for the first switch
Find the request factory your application actually uses, including the transport behind any wrappers. Keep it and its settings for the first switch if you can. A bare RestClient.builder() can pick a different factory based on the classpath. Request factory selection
The lab uses SimpleClientHttpRequestFactory with the JDK's HttpURLConnection. Its connect timeout gives the connection two seconds to open. Its read timeout gives a read one second to receive data. A response that keeps sending data can take longer overall. The simple factory exposes no pool wait setting. With pooled Apache HttpClient 5, setConnectionRequestTimeout limits how long a request waits for a connection, and the Spring read timeout sets Apache's response timeout. Check redirects, proxy routing and TLS settings for the transport you actually deploy. Simple factory Javadoc · Apache factory Javadoc
Keep interceptor order and message converters in view. In the lab, one interceptor writes a correlation header and the next appends /partner. The server checks the resulting value. In production, also verify auth headers and signing, representative request and response bodies, and the metrics and traces you rely on.
In a Boot application, start with its injected RestClient.Builder where available. Boot preconfigures the factory and converters and can apply customizers for things like observation. The lab builds its client directly and sets the transport, URI factory, interceptors and status handler explicitly. Calling REST services with Spring Boot
Run the lab and reproduce the 503 bug
Download the Maven lab ZIP. Extract it, open the directory containing pom.xml, and run the commands below with a maintained JDK 21 and Maven 3.9.11. The first run needs Maven Central or an equivalent mirror.
java -version
mvn -version
mvn test
mvn -Dtest=ShippingContractTest#exchangeRegressionIsDetectedBySame503Assertion -Dlab.broken=true test
The normal suite runs 40 tests. The last command deliberately runs the 503 assertion against the broken adapter, so expect it to fail. In PowerShell, quote both -D... arguments. The regression test uses MockRestServiceServer to return a stub 503 and inspect the request. That tool installs a mock factory and exercises the request and response mapping in isolation. Spring client-testing reference
The timeout test needs a real connection. A local server accepts the GET and holds back the response headers. The test checks for a SocketTimeoutException with a generous time bound. Add separate scenarios for things your application relies on, such as pool saturation or timeouts while reading a body. For tests of your own server endpoints, use RestTestClient against the running app or via Spring MVC's MockMvc. RestTestClient reference
Switch over one integration at a time
- Capture the baseline. Record the old adapter and configuration. Measure successful results, empty results, upstream errors, timeouts and latency. Set thresholds and an observation window before you start.
- Compare both clients. Run the same tests and compare similar traffic. For example, a drop in reported 503 errors alongside a rise in empty results is worth investigating.
- Start small. Send each request to one adapter. If the mapping changes or the timeout rate or p95 latency exceeds your threshold, switch back to the previous adapter and its configuration. Rehearse that rollback before expanding traffic.
- Remove the old client. Once the rollback window closes, remove the bridge and keep the contract tests.
Compare writes by routing each request to a single adapter. Treat retries as a separate change with their own budget and idempotency rules. The Request Timed Out. Did the Order Fail?