Deprecate RestTemplate and related types

As announced in "the state of HTTP clients in Spring" blog post
(https://spring.io/blog/2025/09/30/the-state-of-http-clients-in-spring),
the deprecation timeline for `RestTemplate` was announced last November
and docs were updated accordingly.

This commit `@Deprecate` `RestTemplate` and related types for removal to
send a stronger signal to our community.
The actual removal is scheduled for Spring Framework 8.0 (not yet
scheduled).

Closes gh-36574
This commit is contained in:
Brian Clozel
2026-03-31 12:28:44 +02:00
parent 7473cd5fbc
commit 83c2afb643
35 changed files with 91 additions and 10 deletions
@@ -152,7 +152,10 @@ public final class MockRestServiceServer {
* Return a builder for a {@code MockRestServiceServer} that should be used
* to reply to the given {@code RestTemplate}.
* @since 4.3
* @deprecated as of 7.1 in favor of {@link #bindTo(RestClient.Builder)}.
*/
@Deprecated(since = "7.1", forRemoval = true)
@SuppressWarnings("removal")
public static MockRestServiceServerBuilder bindTo(RestTemplate restTemplate) {
return new RestTemplateMockRestServiceServerBuilder(restTemplate);
}
@@ -161,7 +164,10 @@ public final class MockRestServiceServer {
* Return a builder for a {@code MockRestServiceServer} that should be used
* to reply to the {@code RestTemplate} for the given {@code RestGatewaySupport}.
* @since 4.3
* @deprecated as of 7.1 in favor of {@link #bindTo(RestClient.Builder)}.
*/
@Deprecated(since = "7.1", forRemoval = true)
@SuppressWarnings("removal")
public static MockRestServiceServerBuilder bindTo(RestGatewaySupport restGatewaySupport) {
Assert.notNull(restGatewaySupport, "'restGatewaySupport' must not be null");
return new RestTemplateMockRestServiceServerBuilder(restGatewaySupport.getRestTemplate());
@@ -182,7 +188,10 @@ public final class MockRestServiceServer {
* A shortcut for {@code bindTo(restTemplate).build()}.
* @param restTemplate the RestTemplate to set up for mock testing
* @return the mock server
* @deprecated as of 7.1 in favor of {@link #bindTo(RestClient.Builder)}.
*/
@Deprecated(since = "7.1", forRemoval = true)
@SuppressWarnings("removal")
public static MockRestServiceServer createServer(RestTemplate restTemplate) {
return bindTo(restTemplate).build();
}
@@ -191,7 +200,10 @@ public final class MockRestServiceServer {
* A shortcut for {@code bindTo(restGateway).build()}.
* @param restGateway the REST gateway to set up for mock testing
* @return the mock server
* @deprecated as of 7.1 in favor of {@link #bindTo(RestClient.Builder)}.
*/
@Deprecated(since = "7.1", forRemoval = true)
@SuppressWarnings("removal")
public static MockRestServiceServer createServer(RestGatewaySupport restGateway) {
return bindTo(restGateway).build();
}
@@ -300,7 +312,7 @@ public final class MockRestServiceServer {
}
}
@SuppressWarnings("removal")
private static class RestTemplateMockRestServiceServerBuilder extends AbstractMockRestServiceServerBuilder {
private final RestTemplate restTemplate;
@@ -47,7 +47,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
* @author Juergen Hoeller
*/
@SpringJUnitWebConfig
@SuppressWarnings("deprecation")
@SuppressWarnings({"deprecation", "removal"})
class MockMvcClientHttpRequestFactoryTests {
private final RestTemplate template;