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:26:11 +02:00
parent 7473cd5fbc
commit 83c2afb643
35 changed files with 91 additions and 10 deletions
@@ -35,6 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Brian Clozel
*/
@SuppressWarnings("removal")
class InterceptingHttpAccessorTests {
@Test
@@ -57,6 +57,7 @@ import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY;
* Tests for {@link DefaultResponseErrorHandler} handling of specific
* HTTP status codes.
*/
@SuppressWarnings("removal")
class DefaultResponseErrorHandlerHttpStatusTests {
private final DefaultResponseErrorHandler handler = new DefaultResponseErrorHandler();
@@ -44,6 +44,7 @@ import static org.mockito.Mockito.mock;
* @author Juergen Hoeller
* @author Denys Ivano
*/
@SuppressWarnings("removal")
class DefaultResponseErrorHandlerTests {
private final DefaultResponseErrorHandler handler = new DefaultResponseErrorHandler();
@@ -44,7 +44,7 @@ import static org.mockito.Mockito.mock;
*
* @author Arjen Poutsma
*/
@SuppressWarnings("ALL")
@SuppressWarnings("removal")
class ExtractingResponseErrorHandlerTests {
private ExtractingResponseErrorHandler errorHandler;
@@ -52,6 +52,7 @@ import static org.mockito.Mockito.mock;
* @author Brian Clozel
* @author Sam Brannen
*/
@SuppressWarnings("removal")
class HttpMessageConverterExtractorTests {
private final HttpMessageConverter<String> converter = mock();
@@ -49,7 +49,7 @@ import static org.assertj.core.api.Assertions.fail;
*/
class RestClientBuilderTests {
@SuppressWarnings("unchecked")
@SuppressWarnings({"unchecked", "removal"})
@Test
void createFromRestTemplate() {
JettyClientHttpRequestFactory requestFactory = new JettyClientHttpRequestFactory();
@@ -90,6 +90,7 @@ class RestClientBuilderTests {
}
@Test
@SuppressWarnings("removal")
void defaultUriBuilderFactory() {
RestTemplate restTemplate = new RestTemplate();
@@ -82,6 +82,7 @@ import static org.springframework.http.MediaType.MULTIPART_MIXED;
* @author Brian Clozel
* @author Sam Brannen
*/
@SuppressWarnings("removal")
class RestTemplateIntegrationTests extends AbstractMockWebServerTests {
@Retention(RetentionPolicy.RUNTIME)
@@ -55,6 +55,7 @@ import static org.springframework.http.HttpMethod.GET;
* Tests for the client HTTP observations with {@link RestTemplate}.
* @author Brian Clozel
*/
@SuppressWarnings("removal")
class RestTemplateObservationTests {
@@ -83,7 +83,7 @@ import static org.springframework.http.MediaType.parseMediaType;
* @author Brian Clozel
* @author Sam Brannen
*/
@SuppressWarnings("unchecked")
@SuppressWarnings({"unchecked", "removal"})
class RestTemplateTests {
private final ClientHttpRequestFactory requestFactory = mock();
@@ -80,7 +80,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
* @author Rossen Stoyanchev
* @author Brian Clozel
*/
@SuppressWarnings("JUnitMalformedDeclaration")
@SuppressWarnings({"JUnitMalformedDeclaration", "removal"})
class RestClientAdapterTests {
private final MockWebServer anotherServer = new MockWebServer();
@@ -34,6 +34,7 @@ import kotlin.reflect.jvm.kotlinFunction
*
* @author Sebastien Deleuze
*/
@Suppress("REMOVAL", "DEPRECATION")
class RestOperationsExtensionsTests {
val template = mockk<RestOperations>()
@@ -28,7 +28,6 @@ import org.springframework.http.ResponseEntity
import org.springframework.util.LinkedMultiValueMap
import org.springframework.util.MultiValueMap
import org.springframework.web.bind.annotation.*
import org.springframework.web.client.RestTemplate
import org.springframework.web.multipart.MultipartFile
import org.springframework.web.service.annotation.GetExchange
import org.springframework.web.service.annotation.PostExchange
@@ -46,6 +45,7 @@ import java.util.*
*
* @author Olga Maciaszek-Sharma
*/
@Suppress("REMOVAL", "DEPRECATION")
class KotlinRestTemplateHttpServiceProxyTests {
private lateinit var server: MockWebServer
@@ -65,7 +65,7 @@ class KotlinRestTemplateHttpServiceProxyTests {
}
private fun initTestService(): TestService {
val restTemplate = RestTemplate()
val restTemplate = org.springframework.web.client.RestTemplate()
restTemplate.uriTemplateHandler = DefaultUriBuilderFactory(server.url("/").toString())
return HttpServiceProxyFactory.builder()
.exchangeAdapter(RestTemplateAdapter.create(restTemplate))