Skip to content

Commit 3959c56

Browse files
committed
Deprecate RestTemplate support
With Spring Framework 7.1 deprecating RestTemplate for removal, this commit deprecates our supporting infrastructure as well, and steers users towards RestClient instead: * RestTemplateAutoConfiguration and RestTemplateObservationAutoConfiguration * RestTemplateBuilder, RestTemplateBuilderConfigurer, and RestTemplateBuilderClientHttpRequestInitializer * RestTemplateCustomizer, RestTemplateRequestCustomizer, and ObservationRestTemplateCustomizer * MockRestServiceServerAutoConfiguration, MockServerRestTemplateCustomizer, and RootUriRequestExpectationManager in the test support module The reference documentation no longer covers RestTemplate and now solely documents RestClient and WebClient. Code snippets and sample tests that only existed to illustrate RestTemplate usage have been removed accordingly. Closes gh-51118
1 parent 2a8da4b commit 3959c56

67 files changed

Lines changed: 137 additions & 479 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

documentation/spring-boot-docs/src/docs/antora/modules/ROOT/pages/documentation.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ If your application needs IO capabilities, see one or more of the following sect
106106
* *Quartz:* xref:reference:io/quartz.adoc[Quartz Scheduling]
107107
* *Mail:* xref:reference:io/email.adoc[Sending Email]
108108
* *Validation:* xref:reference:io/validation.adoc[JSR-303 Validation]
109-
* *REST Clients:* xref:reference:io/rest-client.adoc[Calling REST Services with RestTemplate and WebClient]
109+
* *REST Clients:* xref:reference:io/rest-client.adoc[Calling REST Services with RestClient and WebClient]
110110
* *Webservices:* xref:reference:io/webservices.adoc[Auto-configuration for Spring Web Services]
111111
* *JTA:* xref:reference:io/jta.adoc[Distributed Transactions with JTA]
112112

documentation/spring-boot-docs/src/docs/antora/modules/ROOT/pages/redirect.adoc

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -539,8 +539,6 @@
539539
* xref:how-to:hotswapping.adoc#howto.hotswapping.reload-templates[#howto.hotswapping.reload-templates]
540540
* xref:how-to:hotswapping.adoc#howto.hotswapping[#howto-hotswapping]
541541
* xref:how-to:hotswapping.adoc#howto.hotswapping[#howto.hotswapping]
542-
* xref:how-to:http-clients.adoc#howto.http-clients.rest-template-proxy-configuration[#howto-http-clients-proxy-configuration]
543-
* xref:how-to:http-clients.adoc#howto.http-clients.rest-template-proxy-configuration[#howto.http-clients.rest-template-proxy-configuration]
544542
* xref:how-to:http-clients.adoc#howto.http-clients.webclient-reactor-netty-customization[#howto-webclient-reactor-netty-customization]
545543
* xref:how-to:http-clients.adoc#howto.http-clients.webclient-reactor-netty-customization[#howto.http-clients.webclient-reactor-netty-customization]
546544
* xref:how-to:http-clients.adoc#howto.http-clients[#howto-http-clients]
@@ -1682,13 +1680,6 @@
16821680
* xref:reference:io/rest-client.adoc#io.rest-client.restclient.customization[#io.rest-client.restclient.customization]
16831681
* xref:reference:io/rest-client.adoc#io.rest-client.restclient.ssl[#io.rest-client.restclient.ssl]
16841682
* xref:reference:io/rest-client.adoc#io.rest-client.restclient[#io.rest-client.restclient]
1685-
* xref:reference:io/rest-client.adoc#io.rest-client.resttemplate.customization[#boot-features-resttemplate-customization]
1686-
* xref:reference:io/rest-client.adoc#io.rest-client.resttemplate.customization[#features.resttemplate.customization]
1687-
* xref:reference:io/rest-client.adoc#io.rest-client.resttemplate.customization[#io.rest-client.resttemplate.customization]
1688-
* xref:reference:io/rest-client.adoc#io.rest-client.resttemplate.ssl[#io.rest-client.resttemplate.ssl]
1689-
* xref:reference:io/rest-client.adoc#io.rest-client.resttemplate[#boot-features-resttemplate]
1690-
* xref:reference:io/rest-client.adoc#io.rest-client.resttemplate[#features.resttemplate]
1691-
* xref:reference:io/rest-client.adoc#io.rest-client.resttemplate[#io.rest-client.resttemplate]
16921683
* xref:reference:io/rest-client.adoc#io.rest-client.webclient.customization[#boot-features-webclient-customization]
16931684
* xref:reference:io/rest-client.adoc#io.rest-client.webclient.customization[#features.webclient.customization]
16941685
* xref:reference:io/rest-client.adoc#io.rest-client.webclient.customization[#io.rest-client.webclient.customization]

documentation/spring-boot-docs/src/docs/antora/modules/how-to/pages/http-clients.adoc

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,6 @@ This section answers questions related to using them.
66

77

88

9-
[[howto.http-clients.rest-template-proxy-configuration]]
10-
== Configure RestTemplate to Use a Proxy
11-
12-
As described in xref:reference:io/rest-client.adoc#io.rest-client.resttemplate.customization[RestTemplate Customization], you can use a javadoc:org.springframework.boot.restclient.RestTemplateCustomizer[] with javadoc:org.springframework.boot.restclient.RestTemplateBuilder[] to build a customized javadoc:org.springframework.web.client.RestTemplate[].
13-
This is the recommended approach for creating a javadoc:org.springframework.web.client.RestTemplate[] configured to use a proxy.
14-
15-
The exact details of the proxy configuration depend on the underlying client request factory that is being used.
16-
17-
18-
199
[[howto.http-clients.webclient-reactor-netty-customization]]
2010
== Configure the TcpClient used by a Reactor Netty-based WebClient
2111

documentation/spring-boot-docs/src/docs/antora/modules/how-to/pages/spring-mvc.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ Spring uses javadoc:org.springframework.boot.http.converter.autoconfigure.HttpMe
135135
You can contribute additional converters by adding beans of the appropriate type in a Spring Boot context.
136136
If a bean you add is of a type that would have been included by default anyway (such as javadoc:org.springframework.http.converter.json.JacksonJsonHttpMessageConverter[] for JSON conversions), it replaces the default value.
137137
A convenience bean of type javadoc:org.springframework.boot.http.converter.autoconfigure.HttpMessageConverters[] is provided and is always available if you use the default MVC configuration.
138-
It has some useful methods to access the default and user-enhanced message converters (For example, it can be useful if you want to manually inject them into a custom javadoc:org.springframework.web.client.RestTemplate[]).
138+
It has some useful methods to access the default and user-enhanced message converters (For example, it can be useful if you want to manually inject them into a custom javadoc:org.springframework.web.client.RestClient[]).
139139

140140
As in normal MVC usage, any javadoc:org.springframework.web.servlet.config.annotation.WebMvcConfigurer[] beans that you provide can also contribute converters by overriding the `configureMessageConverters` method.
141141
However, unlike with normal MVC, you can supply only additional converters that you need (because Spring Boot uses the same mechanism to contribute its defaults).

documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/actuator/metrics.adoc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -840,21 +840,20 @@ This metric is tagged with the following information:
840840
[[actuator.metrics.supported.http-clients]]
841841
=== HTTP Client Metrics
842842

843-
Spring Boot Actuator manages the instrumentation of javadoc:org.springframework.web.client.RestTemplate[], javadoc:org.springframework.web.reactive.function.client.WebClient[] and javadoc:org.springframework.web.client.RestClient[].
843+
Spring Boot Actuator manages the instrumentation of javadoc:org.springframework.web.reactive.function.client.WebClient[] and javadoc:org.springframework.web.client.RestClient[].
844844
For that, you have to inject the auto-configured builder and use it to create instances:
845845

846-
* javadoc:org.springframework.boot.restclient.RestTemplateBuilder[] for javadoc:org.springframework.web.client.RestTemplate[]
847846
* javadoc:org.springframework.web.reactive.function.client.WebClient$Builder[] for javadoc:org.springframework.web.reactive.function.client.WebClient[]
848847
* javadoc:org.springframework.web.client.RestClient$Builder[] for javadoc:org.springframework.web.client.RestClient[]
849848

850-
You can also manually apply the customizers responsible for this instrumentation, namely javadoc:org.springframework.boot.restclient.observation.ObservationRestTemplateCustomizer[], javadoc:org.springframework.boot.webclient.observation.ObservationWebClientCustomizer[] and javadoc:org.springframework.boot.restclient.observation.ObservationRestClientCustomizer[].
849+
You can also manually apply the customizers responsible for this instrumentation, namely javadoc:org.springframework.boot.webclient.observation.ObservationWebClientCustomizer[] and javadoc:org.springframework.boot.restclient.observation.ObservationRestClientCustomizer[].
851850

852851
By default, metrics are generated with the name, `http.client.requests`.
853852
You can customize the name by setting the configprop:management.observations.http.client.requests.name[] property.
854853

855854
See the {url-spring-framework-docs}/integration/observability.html#observability.http-client[Spring Framework reference documentation for more information on produced observations].
856855

857-
To customize the tags when using javadoc:org.springframework.web.client.RestTemplate[] or javadoc:org.springframework.web.client.RestClient[], provide a javadoc:org.springframework.context.annotation.Bean[format=annotation] that implements javadoc:org.springframework.http.client.observation.ClientRequestObservationConvention[] from the `org.springframework.http.client.observation` package.
856+
To customize the tags when using javadoc:org.springframework.web.client.RestClient[], provide a javadoc:org.springframework.context.annotation.Bean[format=annotation] that implements javadoc:org.springframework.http.client.observation.ClientRequestObservationConvention[] from the `org.springframework.http.client.observation` package.
858857
To customize the tags when using javadoc:org.springframework.web.reactive.function.client.WebClient[], provide a javadoc:org.springframework.context.annotation.Bean[format=annotation] that implements javadoc:org.springframework.web.reactive.function.client.ClientRequestObservationConvention[] from the `org.springframework.web.reactive.function.client` package.
859858

860859

documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/actuator/tracing.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ Please read xref:reference:actuator/observability.adoc#actuator.observability.co
9797
[[actuator.micrometer-tracing.propagating-traces]]
9898
== Propagating Traces
9999

100-
To automatically propagate traces over the network, use the auto-configured xref:io/rest-client.adoc#io.rest-client.resttemplate[`RestTemplateBuilder`], xref:io/rest-client.adoc#io.rest-client.restclient[`RestClient.Builder`] or xref:io/rest-client.adoc#io.rest-client.webclient[`WebClient.Builder`] to construct the client.
100+
To automatically propagate traces over the network, use the auto-configured xref:io/rest-client.adoc#io.rest-client.restclient[`RestClient.Builder`] or xref:io/rest-client.adoc#io.rest-client.webclient[`WebClient.Builder`] to construct the client.
101101

102-
WARNING: If you create the javadoc:org.springframework.web.client.RestTemplate[], the javadoc:org.springframework.web.client.RestClient[] or the javadoc:org.springframework.web.reactive.function.client.WebClient[] without using the auto-configured builders, automatic trace propagation won't work!
102+
WARNING: If you create the javadoc:org.springframework.web.client.RestClient[] or the javadoc:org.springframework.web.reactive.function.client.WebClient[] without using the auto-configured builders, automatic trace propagation won't work!
103103

104104

105105

documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/io/rest-client.adoc

Lines changed: 3 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
Spring Boot provides various convenient ways to call remote REST services.
55
If you are developing a non-blocking reactive application and you're using Spring WebFlux, then you can use javadoc:org.springframework.web.reactive.function.client.WebClient[].
6-
If you prefer imperative APIs then you can use javadoc:org.springframework.web.client.RestClient[] or javadoc:org.springframework.web.client.RestTemplate[].
6+
If you prefer imperative APIs then you can use javadoc:org.springframework.web.client.RestClient[].
77

88

99

@@ -159,67 +159,10 @@ include-code::settings/MyService[]
159159

160160

161161

162-
[[io.rest-client.resttemplate]]
163-
== RestTemplate
164-
165-
Spring Framework's javadoc:org.springframework.web.client.RestTemplate[] class predates javadoc:org.springframework.web.client.RestClient[] and is the classic way that many applications use to call remote REST services.
166-
You might choose to use javadoc:org.springframework.web.client.RestTemplate[] when you have existing code that you don't want to migrate to javadoc:org.springframework.web.client.RestClient[], or because you're already familiar with the javadoc:org.springframework.web.client.RestTemplate[] API.
167-
168-
Since javadoc:org.springframework.web.client.RestTemplate[] instances often need to be customized before being used, Spring Boot does not provide any single auto-configured javadoc:org.springframework.web.client.RestTemplate[] bean.
169-
It does, however, auto-configure a javadoc:org.springframework.boot.restclient.RestTemplateBuilder[], which can be used to create javadoc:org.springframework.web.client.RestTemplate[] instances when needed.
170-
The auto-configured javadoc:org.springframework.boot.restclient.RestTemplateBuilder[] ensures that sensible javadoc:org.springframework.boot.http.converter.autoconfigure.HttpMessageConverters[] and an appropriate javadoc:org.springframework.http.client.ClientHttpRequestFactory[] are applied to javadoc:org.springframework.web.client.RestTemplate[] instances.
171-
172-
The following code shows a typical example:
173-
174-
include-code::MyService[]
175-
176-
javadoc:org.springframework.boot.restclient.RestTemplateBuilder[] includes a number of useful methods that can be used to quickly configure a javadoc:org.springframework.web.client.RestTemplate[].
177-
For example, to add BASIC authentication support, you can use `builder.basicAuthentication("user", "password").build()`.
178-
179-
180-
181-
[[io.rest-client.resttemplate.customization]]
182-
=== RestTemplate Customization
183-
184-
There are three main approaches to javadoc:org.springframework.web.client.RestTemplate[] customization, depending on how broadly you want the customizations to apply.
185-
186-
To make the scope of any customizations as narrow as possible, inject the auto-configured javadoc:org.springframework.boot.restclient.RestTemplateBuilder[] and then call its methods as required.
187-
Each method call returns a new javadoc:org.springframework.boot.restclient.RestTemplateBuilder[] instance, so the customizations only affect this use of the builder.
188-
189-
To make an application-wide, additive customization, use a javadoc:org.springframework.boot.restclient.RestTemplateCustomizer[] bean.
190-
All such beans are automatically registered with the auto-configured javadoc:org.springframework.boot.restclient.RestTemplateBuilder[] and are applied to any templates that are built with it.
191-
192-
The following example shows a customizer that configures the use of a proxy for all hosts except `192.168.0.5`:
193-
194-
include-code::MyRestTemplateCustomizer[]
195-
196-
Finally, you can define your own javadoc:org.springframework.boot.restclient.RestTemplateBuilder[] bean.
197-
Doing so will replace the auto-configured builder.
198-
If you want any javadoc:org.springframework.boot.restclient.RestTemplateCustomizer[] beans to be applied to your custom builder, as the auto-configuration would have done, configure it using a javadoc:org.springframework.boot.restclient.autoconfigure.RestTemplateBuilderConfigurer[].
199-
The following example exposes a javadoc:org.springframework.boot.restclient.RestTemplateBuilder[] that matches what Spring Boot's auto-configuration would have done, except that custom connect and read timeouts are also specified:
200-
201-
include-code::MyRestTemplateBuilderConfiguration[]
202-
203-
The most extreme (and rarely used) option is to create your own javadoc:org.springframework.boot.restclient.RestTemplateBuilder[] bean without using a configurer.
204-
In addition to replacing the auto-configured builder, this also prevents any javadoc:org.springframework.boot.restclient.RestTemplateCustomizer[] beans from being used.
205-
206-
TIP: You can also change the xref:io/rest-client.adoc#io.rest-client.clienthttprequestfactory.configuration[global HTTP client configuration].
207-
208-
209-
210-
[[io.rest-client.resttemplate.ssl]]
211-
=== RestTemplate SSL Support
212-
213-
If you need custom SSL configuration on the javadoc:org.springframework.web.client.RestTemplate[], you can apply an xref:features/ssl.adoc#features.ssl.bundles[SSL bundle] to the javadoc:org.springframework.boot.restclient.RestTemplateBuilder[] as shown in this example:
214-
215-
include-code::MyService[]
216-
217-
218-
219162
[[io.rest-client.clienthttprequestfactory]]
220-
== HTTP Client Detection for RestClient and RestTemplate
163+
== HTTP Client Detection for RestClient
221164

222-
Spring Boot will auto-detect which HTTP client to use with javadoc:org.springframework.web.client.RestClient[] and javadoc:org.springframework.web.client.RestTemplate[] depending on the libraries available on the application classpath.
165+
Spring Boot will auto-detect which HTTP client to use with javadoc:org.springframework.web.client.RestClient[] depending on the libraries available on the application classpath.
223166
In order of preference, the following clients are supported:
224167

225168
. Apache HttpClient

documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/packaging/native-image/advanced-topics.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ You can then use javadoc:org.springframework.context.annotation.ImportRuntimeHin
168168

169169
If you have classes which need binding (mostly needed when serializing or deserializing JSON), you can use {url-spring-framework-docs}/core/aot.html#aot.hints.register-reflection-for-binding[`@RegisterReflectionForBinding`] on any bean.
170170
Most of the hints are automatically inferred, for example when accepting or returning data from a javadoc:org.springframework.web.bind.annotation.RestController[format=annotation] method.
171-
But when you work with javadoc:org.springframework.web.reactive.function.client.WebClient[], javadoc:org.springframework.web.client.RestClient[] or javadoc:org.springframework.web.client.RestTemplate[] directly, you might need to use javadoc:org.springframework.aot.hint.annotation.RegisterReflectionForBinding[format=annotation].
171+
But when you work with javadoc:org.springframework.web.reactive.function.client.WebClient[] or javadoc:org.springframework.web.client.RestClient[] directly, you might need to use javadoc:org.springframework.aot.hint.annotation.RegisterReflectionForBinding[format=annotation].
172172

173173

174174

documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/testing/spring-boot-applications.adoc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -732,19 +732,15 @@ include-code::server/MyDataLdapTests[]
732732
== Auto-configured REST Clients
733733

734734
You can use the javadoc:org.springframework.boot.restclient.test.autoconfigure.RestClientTest[format=annotation] annotation from the `spring-boot-restclient-test` module to test REST clients.
735-
By default, it auto-configures Jackson, GSON, and Jsonb support, configures a javadoc:org.springframework.boot.restclient.RestTemplateBuilder[] and a javadoc:org.springframework.web.client.RestClient$Builder[], and adds support for javadoc:org.springframework.test.web.client.MockRestServiceServer[].
735+
By default, it auto-configures Jackson, GSON, and Jsonb support, configures a javadoc:org.springframework.web.client.RestClient$Builder[], and adds support for javadoc:org.springframework.test.web.client.MockRestServiceServer[].
736736
Regular javadoc:org.springframework.stereotype.Component[format=annotation] and javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans are not scanned when the javadoc:org.springframework.boot.restclient.test.autoconfigure.RestClientTest[format=annotation] annotation is used.
737737
javadoc:org.springframework.boot.context.properties.EnableConfigurationProperties[format=annotation] can be used to include javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans.
738738

739739
TIP: A list of the auto-configuration settings that are enabled by javadoc:org.springframework.boot.restclient.test.autoconfigure.RestClientTest[format=annotation] can be xref:appendix:test-auto-configuration/index.adoc[found in the appendix].
740740

741741
The specific beans that you want to test should be specified by using the `value` or `components` attribute of javadoc:org.springframework.boot.restclient.test.autoconfigure.RestClientTest[format=annotation].
742742

743-
When using a javadoc:org.springframework.boot.restclient.RestTemplateBuilder[] in the beans under test and `RestTemplateBuilder.baseUri(String baseUri)` has been called when building the javadoc:org.springframework.web.client.RestTemplate[], then the base URI should be omitted from the javadoc:org.springframework.test.web.client.MockRestServiceServer[] expectations as shown in the following example:
744-
745-
include-code::MyRestTemplateServiceTests[]
746-
747-
When using a javadoc:org.springframework.web.client.RestClient$Builder[] in the beans under test, or when using a javadoc:org.springframework.boot.restclient.RestTemplateBuilder[] without calling `baseUri(String baseUri)`, the full URI must be used in the javadoc:org.springframework.test.web.client.MockRestServiceServer[] expectations as shown in the following example:
743+
When using a javadoc:org.springframework.web.client.RestClient$Builder[] in the beans under test, the full URI must be used in the javadoc:org.springframework.test.web.client.MockRestServiceServer[] expectations as shown in the following example:
748744

749745
include-code::MyRestClientServiceTests[]
750746

documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/io/restclient/resttemplate/Details.java

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)