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
This commit is contained in:
Stéphane Nicoll
2026-07-25 08:32:32 +02:00
parent 2a8da4b465
commit 3959c56bdd
67 changed files with 137 additions and 479 deletions
@@ -106,7 +106,7 @@ If your application needs IO capabilities, see one or more of the following sect
* *Quartz:* xref:reference:io/quartz.adoc[Quartz Scheduling]
* *Mail:* xref:reference:io/email.adoc[Sending Email]
* *Validation:* xref:reference:io/validation.adoc[JSR-303 Validation]
* *REST Clients:* xref:reference:io/rest-client.adoc[Calling REST Services with RestTemplate and WebClient]
* *REST Clients:* xref:reference:io/rest-client.adoc[Calling REST Services with RestClient and WebClient]
* *Webservices:* xref:reference:io/webservices.adoc[Auto-configuration for Spring Web Services]
* *JTA:* xref:reference:io/jta.adoc[Distributed Transactions with JTA]
@@ -539,8 +539,6 @@
* xref:how-to:hotswapping.adoc#howto.hotswapping.reload-templates[#howto.hotswapping.reload-templates]
* xref:how-to:hotswapping.adoc#howto.hotswapping[#howto-hotswapping]
* xref:how-to:hotswapping.adoc#howto.hotswapping[#howto.hotswapping]
* xref:how-to:http-clients.adoc#howto.http-clients.rest-template-proxy-configuration[#howto-http-clients-proxy-configuration]
* xref:how-to:http-clients.adoc#howto.http-clients.rest-template-proxy-configuration[#howto.http-clients.rest-template-proxy-configuration]
* xref:how-to:http-clients.adoc#howto.http-clients.webclient-reactor-netty-customization[#howto-webclient-reactor-netty-customization]
* xref:how-to:http-clients.adoc#howto.http-clients.webclient-reactor-netty-customization[#howto.http-clients.webclient-reactor-netty-customization]
* xref:how-to:http-clients.adoc#howto.http-clients[#howto-http-clients]
@@ -1682,13 +1680,6 @@
* xref:reference:io/rest-client.adoc#io.rest-client.restclient.customization[#io.rest-client.restclient.customization]
* xref:reference:io/rest-client.adoc#io.rest-client.restclient.ssl[#io.rest-client.restclient.ssl]
* xref:reference:io/rest-client.adoc#io.rest-client.restclient[#io.rest-client.restclient]
* xref:reference:io/rest-client.adoc#io.rest-client.resttemplate.customization[#boot-features-resttemplate-customization]
* xref:reference:io/rest-client.adoc#io.rest-client.resttemplate.customization[#features.resttemplate.customization]
* xref:reference:io/rest-client.adoc#io.rest-client.resttemplate.customization[#io.rest-client.resttemplate.customization]
* xref:reference:io/rest-client.adoc#io.rest-client.resttemplate.ssl[#io.rest-client.resttemplate.ssl]
* xref:reference:io/rest-client.adoc#io.rest-client.resttemplate[#boot-features-resttemplate]
* xref:reference:io/rest-client.adoc#io.rest-client.resttemplate[#features.resttemplate]
* xref:reference:io/rest-client.adoc#io.rest-client.resttemplate[#io.rest-client.resttemplate]
* xref:reference:io/rest-client.adoc#io.rest-client.webclient.customization[#boot-features-webclient-customization]
* xref:reference:io/rest-client.adoc#io.rest-client.webclient.customization[#features.webclient.customization]
* xref:reference:io/rest-client.adoc#io.rest-client.webclient.customization[#io.rest-client.webclient.customization]
@@ -6,16 +6,6 @@ This section answers questions related to using them.
[[howto.http-clients.rest-template-proxy-configuration]]
== Configure RestTemplate to Use a Proxy
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[].
This is the recommended approach for creating a javadoc:org.springframework.web.client.RestTemplate[] configured to use a proxy.
The exact details of the proxy configuration depend on the underlying client request factory that is being used.
[[howto.http-clients.webclient-reactor-netty-customization]]
== Configure the TcpClient used by a Reactor Netty-based WebClient
@@ -135,7 +135,7 @@ Spring uses javadoc:org.springframework.boot.http.converter.autoconfigure.HttpMe
You can contribute additional converters by adding beans of the appropriate type in a Spring Boot context.
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.
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.
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[]).
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[]).
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.
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).
@@ -840,21 +840,20 @@ This metric is tagged with the following information:
[[actuator.metrics.supported.http-clients]]
=== HTTP Client Metrics
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[].
Spring Boot Actuator manages the instrumentation of javadoc:org.springframework.web.reactive.function.client.WebClient[] and javadoc:org.springframework.web.client.RestClient[].
For that, you have to inject the auto-configured builder and use it to create instances:
* javadoc:org.springframework.boot.restclient.RestTemplateBuilder[] for javadoc:org.springframework.web.client.RestTemplate[]
* javadoc:org.springframework.web.reactive.function.client.WebClient$Builder[] for javadoc:org.springframework.web.reactive.function.client.WebClient[]
* javadoc:org.springframework.web.client.RestClient$Builder[] for javadoc:org.springframework.web.client.RestClient[]
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[].
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[].
By default, metrics are generated with the name, `http.client.requests`.
You can customize the name by setting the configprop:management.observations.http.client.requests.name[] property.
See the {url-spring-framework-docs}/integration/observability.html#observability.http-client[Spring Framework reference documentation for more information on produced observations].
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.
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.
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.
@@ -97,9 +97,9 @@ Please read xref:reference:actuator/observability.adoc#actuator.observability.co
[[actuator.micrometer-tracing.propagating-traces]]
== Propagating Traces
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.
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.
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!
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!
@@ -3,7 +3,7 @@
Spring Boot provides various convenient ways to call remote REST services.
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[].
If you prefer imperative APIs then you can use javadoc:org.springframework.web.client.RestClient[] or javadoc:org.springframework.web.client.RestTemplate[].
If you prefer imperative APIs then you can use javadoc:org.springframework.web.client.RestClient[].
@@ -159,67 +159,10 @@ include-code::settings/MyService[]
[[io.rest-client.resttemplate]]
== RestTemplate
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.
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.
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.
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.
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.
The following code shows a typical example:
include-code::MyService[]
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[].
For example, to add BASIC authentication support, you can use `builder.basicAuthentication("user", "password").build()`.
[[io.rest-client.resttemplate.customization]]
=== RestTemplate Customization
There are three main approaches to javadoc:org.springframework.web.client.RestTemplate[] customization, depending on how broadly you want the customizations to apply.
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.
Each method call returns a new javadoc:org.springframework.boot.restclient.RestTemplateBuilder[] instance, so the customizations only affect this use of the builder.
To make an application-wide, additive customization, use a javadoc:org.springframework.boot.restclient.RestTemplateCustomizer[] bean.
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.
The following example shows a customizer that configures the use of a proxy for all hosts except `192.168.0.5`:
include-code::MyRestTemplateCustomizer[]
Finally, you can define your own javadoc:org.springframework.boot.restclient.RestTemplateBuilder[] bean.
Doing so will replace the auto-configured builder.
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[].
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:
include-code::MyRestTemplateBuilderConfiguration[]
The most extreme (and rarely used) option is to create your own javadoc:org.springframework.boot.restclient.RestTemplateBuilder[] bean without using a configurer.
In addition to replacing the auto-configured builder, this also prevents any javadoc:org.springframework.boot.restclient.RestTemplateCustomizer[] beans from being used.
TIP: You can also change the xref:io/rest-client.adoc#io.rest-client.clienthttprequestfactory.configuration[global HTTP client configuration].
[[io.rest-client.resttemplate.ssl]]
=== RestTemplate SSL Support
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:
include-code::MyService[]
[[io.rest-client.clienthttprequestfactory]]
== HTTP Client Detection for RestClient and RestTemplate
== HTTP Client Detection for RestClient
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.
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.
In order of preference, the following clients are supported:
. Apache HttpClient
@@ -168,7 +168,7 @@ You can then use javadoc:org.springframework.context.annotation.ImportRuntimeHin
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.
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.
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].
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].
@@ -732,7 +732,7 @@ include-code::server/MyDataLdapTests[]
== Auto-configured REST Clients
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.
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[].
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[].
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.
javadoc:org.springframework.boot.context.properties.EnableConfigurationProperties[format=annotation] can be used to include javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans.
@@ -740,11 +740,7 @@ TIP: A list of the auto-configuration settings that are enabled by javadoc:org.s
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].
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:
include-code::MyRestTemplateServiceTests[]
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:
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:
include-code::MyRestClientServiceTests[]
@@ -1,21 +0,0 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.docs.io.restclient.resttemplate;
public class Details {
}
@@ -1,36 +0,0 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.docs.io.restclient.resttemplate;
import org.springframework.boot.restclient.RestTemplateBuilder;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
@Service
public class MyService {
private final RestTemplate restTemplate;
public MyService(RestTemplateBuilder restTemplateBuilder) {
this.restTemplate = restTemplateBuilder.build();
}
public Details someRestCall(String name) {
return this.restTemplate.getForObject("/{name}/details", Details.class, name);
}
}
@@ -1,36 +0,0 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.docs.io.restclient.resttemplate.customization;
import java.time.Duration;
import org.springframework.boot.restclient.RestTemplateBuilder;
import org.springframework.boot.restclient.autoconfigure.RestTemplateBuilderConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration(proxyBeanMethods = false)
public class MyRestTemplateBuilderConfiguration {
@Bean
public RestTemplateBuilder restTemplateBuilder(RestTemplateBuilderConfigurer configurer) {
return configurer.configure(new RestTemplateBuilder())
.connectTimeout(Duration.ofSeconds(5))
.readTimeout(Duration.ofSeconds(2));
}
}
@@ -1,56 +0,0 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.docs.io.restclient.resttemplate.customization;
import org.apache.hc.client5.http.classic.HttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.apache.hc.client5.http.impl.routing.DefaultProxyRoutePlanner;
import org.apache.hc.client5.http.routing.HttpRoutePlanner;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.protocol.HttpContext;
import org.springframework.boot.restclient.RestTemplateCustomizer;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
public class MyRestTemplateCustomizer implements RestTemplateCustomizer {
@Override
public void customize(RestTemplate restTemplate) {
HttpRoutePlanner routePlanner = new CustomRoutePlanner(new HttpHost("proxy.example.com"));
HttpClient httpClient = HttpClientBuilder.create().setRoutePlanner(routePlanner).build();
restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient));
}
static class CustomRoutePlanner extends DefaultProxyRoutePlanner {
CustomRoutePlanner(HttpHost proxy) {
super(proxy);
}
@Override
protected HttpHost determineProxy(HttpHost target, HttpContext context) throws HttpException {
if (target.getHostName().equals("192.168.0.5")) {
return null;
}
return super.determineProxy(target, context);
}
}
}
@@ -1,38 +0,0 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.docs.io.restclient.resttemplate.ssl;
import org.springframework.boot.docs.io.restclient.resttemplate.Details;
import org.springframework.boot.restclient.RestTemplateBuilder;
import org.springframework.boot.ssl.SslBundles;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
@Service
public class MyService {
private final RestTemplate restTemplate;
public MyService(RestTemplateBuilder restTemplateBuilder, SslBundles sslBundles) {
this.restTemplate = restTemplateBuilder.sslBundle(sslBundles.getBundle("mybundle")).build();
}
public Details someRestCall(String name) {
return this.restTemplate.getForObject("/{name}/details", Details.class, name);
}
}
@@ -35,6 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@AutoConfigureTestRestTemplate
@SuppressWarnings("removal")
class MySpringBootTests {
@Autowired
@@ -1,20 +0,0 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.docs.io.restclient.resttemplate
class Details
@@ -1,37 +0,0 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.docs.io.restclient.resttemplate
import org.springframework.boot.restclient.RestTemplateBuilder
import org.springframework.stereotype.Service
import org.springframework.web.client.RestTemplate
@Service
class MyService(restTemplateBuilder: RestTemplateBuilder) {
private val restTemplate: RestTemplate
init {
restTemplate = restTemplateBuilder.build()
}
fun someRestCall(name: String): Details {
return restTemplate.getForObject("/{name}/details", Details::class.java, name)!!
}
}
@@ -1,35 +0,0 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.docs.io.restclient.resttemplate.customization
import org.springframework.boot.restclient.autoconfigure.RestTemplateBuilderConfigurer
import org.springframework.boot.restclient.RestTemplateBuilder
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import java.time.Duration
@Configuration(proxyBeanMethods = false)
class MyRestTemplateBuilderConfiguration {
@Bean
fun restTemplateBuilder(configurer: RestTemplateBuilderConfigurer): RestTemplateBuilder {
return configurer.configure(RestTemplateBuilder()).connectTimeout(Duration.ofSeconds(5))
.readTimeout(Duration.ofSeconds(2))
}
}
@@ -1,51 +0,0 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.docs.io.restclient.resttemplate.customization
import org.apache.hc.client5.http.classic.HttpClient
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder
import org.apache.hc.client5.http.impl.routing.DefaultProxyRoutePlanner
import org.apache.hc.client5.http.routing.HttpRoutePlanner
import org.apache.hc.core5.http.HttpException
import org.apache.hc.core5.http.HttpHost
import org.apache.hc.core5.http.protocol.HttpContext
import org.springframework.boot.restclient.RestTemplateCustomizer
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory
import org.springframework.web.client.RestTemplate
class MyRestTemplateCustomizer : RestTemplateCustomizer {
override fun customize(restTemplate: RestTemplate) {
val routePlanner: HttpRoutePlanner = CustomRoutePlanner(HttpHost("proxy.example.com"))
val httpClient: HttpClient = HttpClientBuilder.create().setRoutePlanner(routePlanner).build()
restTemplate.requestFactory = HttpComponentsClientHttpRequestFactory(httpClient)
}
internal class CustomRoutePlanner(proxy: HttpHost?) : DefaultProxyRoutePlanner(proxy) {
@Throws(HttpException::class)
public override fun determineProxy(target: HttpHost, context: HttpContext): HttpHost? {
if (target.hostName == "192.168.0.5") {
return null
}
return super.determineProxy(target, context)
}
}
}
@@ -1,38 +0,0 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.docs.io.restclient.resttemplate.ssl
import org.springframework.boot.docs.io.restclient.resttemplate.Details
import org.springframework.boot.ssl.SslBundles
import org.springframework.boot.restclient.RestTemplateBuilder
import org.springframework.stereotype.Service
import org.springframework.web.client.RestTemplate
@Service
class MyService(restTemplateBuilder: RestTemplateBuilder, sslBundles: SslBundles) {
private val restTemplate: RestTemplate
init {
restTemplate = restTemplateBuilder.sslBundle(sslBundles.getBundle("mybundle")).build()
}
fun someRestCall(name: String): Details {
return restTemplate.getForObject("/{name}/details", Details::class.java, name)!!
}
}
@@ -14,6 +14,8 @@
* limitations under the License.
*/
@file:Suppress("DEPRECATION")
package org.springframework.boot.docs.testing.utilities.testresttemplate
import org.assertj.core.api.Assertions.assertThat
@@ -34,10 +34,12 @@ import static org.assertj.core.api.Assertions.assertThat;
* with a user-defined {@link RestTemplate} that is named {@code testRestTemplate}.
*
* @author Madhura Bhave
* @deprecated since 4.2.0 for removal in 4.4.0
*/
@DirtiesContext
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT,
properties = { "spring.main.web-application-type=reactive", "value=123" })
@Deprecated(since = "4.2.0", forRemoval = true)
class SpringBootTestReactiveWebEnvironmentUserDefinedTestRestTemplateTests
extends AbstractSpringBootTestEmbeddedReactiveWebEnvironmentTests {
@@ -35,9 +35,11 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Phillip Webb
* @author Andy Wilkinson
* @deprecated since 4.2.0 for removal in 4.4.0
*/
@DirtiesContext
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "value=123" })
@Deprecated(since = "4.2.0", forRemoval = true)
class SpringBootTestUserDefinedTestRestTemplateTests extends AbstractSpringBootTestWebServerWebEnvironmentTests {
@Test
@@ -39,6 +39,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
@DirtiesContext
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "value=123" })
@SuppressWarnings("removal")
class SpringBootTestWebEnvironmentRandomPortTests extends AbstractSpringBootTestWebServerWebEnvironmentTests {
@Test
@@ -36,7 +36,6 @@ import org.springframework.boot.health.contributor.Health;
import org.springframework.boot.health.contributor.HealthIndicator;
import org.springframework.boot.http.converter.autoconfigure.HttpMessageConvertersAutoConfiguration;
import org.springframework.boot.jackson.autoconfigure.JacksonAutoConfiguration;
import org.springframework.boot.restclient.autoconfigure.RestTemplateAutoConfiguration;
import org.springframework.boot.security.autoconfigure.SecurityAutoConfiguration;
import org.springframework.boot.security.autoconfigure.web.servlet.ServletWebSecurityAutoConfiguration;
import org.springframework.boot.servlet.autoconfigure.actuate.web.ServletManagementContextAutoConfiguration;
@@ -55,15 +54,14 @@ class CloudFoundryHealthEndpointWebExtensionTests {
private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
.withPropertyValues("VCAP_APPLICATION={}")
.withConfiguration(
AutoConfigurations.of(SecurityAutoConfiguration.class, ServletWebSecurityAutoConfiguration.class,
WebMvcAutoConfiguration.class, JacksonAutoConfiguration.class,
DispatcherServletAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class, RestTemplateAutoConfiguration.class,
ManagementContextAutoConfiguration.class, ServletManagementContextAutoConfiguration.class,
EndpointAutoConfiguration.class, WebEndpointAutoConfiguration.class,
HealthContributorAutoConfiguration.class, HealthContributorRegistryAutoConfiguration.class,
HealthEndpointAutoConfiguration.class, CloudFoundryActuatorAutoConfiguration.class))
.withConfiguration(AutoConfigurations.of(SecurityAutoConfiguration.class,
ServletWebSecurityAutoConfiguration.class, WebMvcAutoConfiguration.class,
JacksonAutoConfiguration.class, DispatcherServletAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class,
ManagementContextAutoConfiguration.class, ServletManagementContextAutoConfiguration.class,
EndpointAutoConfiguration.class, WebEndpointAutoConfiguration.class,
HealthContributorAutoConfiguration.class, HealthContributorRegistryAutoConfiguration.class,
HealthEndpointAutoConfiguration.class, CloudFoundryActuatorAutoConfiguration.class))
.withUserConfiguration(TestHealthIndicator.class);
@Test
@@ -31,7 +31,6 @@ import org.springframework.boot.autoconfigure.info.ProjectInfoAutoConfiguration;
import org.springframework.boot.health.autoconfigure.actuate.endpoint.HealthEndpointAutoConfiguration;
import org.springframework.boot.http.converter.autoconfigure.HttpMessageConvertersAutoConfiguration;
import org.springframework.boot.jackson.autoconfigure.JacksonAutoConfiguration;
import org.springframework.boot.restclient.autoconfigure.RestTemplateAutoConfiguration;
import org.springframework.boot.security.autoconfigure.SecurityAutoConfiguration;
import org.springframework.boot.security.autoconfigure.web.servlet.ServletWebSecurityAutoConfiguration;
import org.springframework.boot.servlet.autoconfigure.actuate.web.ServletManagementContextAutoConfiguration;
@@ -55,9 +54,8 @@ class CloudFoundryInfoEndpointWebExtensionTests {
ServletWebSecurityAutoConfiguration.class, WebMvcAutoConfiguration.class,
JacksonAutoConfiguration.class, DispatcherServletAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class,
RestTemplateAutoConfiguration.class, ManagementContextAutoConfiguration.class,
ServletManagementContextAutoConfiguration.class, EndpointAutoConfiguration.class,
WebEndpointAutoConfiguration.class, ProjectInfoAutoConfiguration.class,
ManagementContextAutoConfiguration.class, ServletManagementContextAutoConfiguration.class,
EndpointAutoConfiguration.class, WebEndpointAutoConfiguration.class, ProjectInfoAutoConfiguration.class,
InfoContributorAutoConfiguration.class, InfoEndpointAutoConfiguration.class,
HealthEndpointAutoConfiguration.class, CloudFoundryActuatorAutoConfiguration.class));
@@ -37,6 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Andy Wilkinson
*/
@SuppressWarnings("removal")
class DevToolsIntegrationTests extends AbstractDevToolsIntegrationTests {
private final TestRestTemplate template = new TestRestTemplate(new RestTemplateBuilder()
@@ -61,7 +61,11 @@ import org.springframework.web.client.RestTemplate;
* @since 4.0.0
* @see #getServer()
* @see #getServer(RestTemplate)
* @deprecated since 4.2.0 for removal in 4.4.0 in favor of
* {@link MockServerRestClientCustomizer}
*/
@Deprecated(since = "4.2.0", forRemoval = true)
@SuppressWarnings("removal")
public class MockServerRestTemplateCustomizer implements RestTemplateCustomizer {
private final Map<RestTemplate, RequestExpectationManager> expectationManagers = new ConcurrentHashMap<>();
@@ -53,7 +53,10 @@ import org.springframework.web.util.UriTemplateHandler;
* @see DefaultUriBuilderFactory
* @see #bindTo(RestTemplate)
* @see #forRestTemplate(RestTemplate, RequestExpectationManager)
* @deprecated since 4.2.0 for removal in 4.4.0 with no replacement
*/
@Deprecated(since = "4.2.0", forRemoval = true)
@SuppressWarnings("removal")
public class RootUriRequestExpectationManager implements RequestExpectationManager {
private final String rootUri;
@@ -51,10 +51,12 @@ import org.springframework.web.client.RestTemplate;
@AutoConfiguration
@ConditionalOnClass(MockServerRestTemplateCustomizer.class)
@ConditionalOnBooleanProperty("spring.test.restclient.mockrestserviceserver.enabled")
@SuppressWarnings("removal")
public final class MockRestServiceServerAutoConfiguration {
@Bean
@ConditionalOnMissingBean
@Deprecated(since = "4.2.0", forRemoval = true)
MockServerRestTemplateCustomizer mockServerRestTemplateCustomizer() {
return new MockServerRestTemplateCustomizer();
}
@@ -40,7 +40,10 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
*
* @author Phillip Webb
* @author Moritz Halbritter
* @deprecated since 4.2.0 for removal in 4.4.0
*/
@Deprecated(since = "4.2.0", forRemoval = true)
@SuppressWarnings("removal")
class MockServerRestTemplateCustomizerTests {
private MockServerRestTemplateCustomizer customizer;
@@ -48,8 +48,11 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
* Tests for {@link RootUriRequestExpectationManager}.
*
* @author Phillip Webb
* @deprecated since 4.2.0 for removal in 4.4.0
*/
@ExtendWith(MockitoExtension.class)
@Deprecated(since = "4.2.0", forRemoval = true)
@SuppressWarnings("removal")
class RootUriRequestExpectationManagerTests {
private final String uri = "https://example.com";
@@ -26,8 +26,11 @@ import org.springframework.web.client.RestTemplate;
* A second example web client used with {@link RestClientTest @RestClientTest} tests.
*
* @author Phillip Webb
* @deprecated since 4.2.0 for removal in 4.4.0
*/
@Service
@Deprecated(since = "4.2.0", forRemoval = true)
@SuppressWarnings("removal")
public class AnotherExampleRestTemplateService {
private final RestTemplate restTemplate;
@@ -41,6 +41,7 @@ class AutoConfigureMockRestServiceServerEnabledFalseIntegrationTests {
private ApplicationContext applicationContext;
@Test
@SuppressWarnings("removal")
void mockServerRestTemplateCustomizerShouldNotBeRegistered() {
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
.isThrownBy(() -> this.applicationContext.getBean(MockServerRestTemplateCustomizer.class));
@@ -40,9 +40,12 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
* {@link RestTemplate} configured with a root URI.
*
* @author Andy Wilkinson
* @deprecated since 4.2.0 for removal in 4.4.0
*/
@SpringBootTest
@AutoConfigureMockRestServiceServer
@Deprecated(since = "4.2.0", forRemoval = true)
@SuppressWarnings("removal")
class AutoConfigureMockRestServiceServerWithRestTemplateRootUriIntegrationTests {
@Autowired
@@ -27,8 +27,11 @@ import org.springframework.web.client.RestTemplate;
* {@link RestClientTest @RestClientTest} tests.
*
* @author Phillip Webb
* @deprecated since 4.2.0 for removal in 4.4.0
*/
@Service
@Deprecated(since = "4.2.0", forRemoval = true)
@SuppressWarnings("removal")
public class ExampleRestTemplateService {
private final RestTemplate restTemplate;
@@ -46,6 +46,8 @@ class MockRestServiceServerAutoConfigurationTests {
}
@Test
@Deprecated(since = "4.2.0", forRemoval = true)
@SuppressWarnings("removal")
void registersMockServerRestTemplateCustomizer() {
this.contextRunner.run((context) -> assertThat(context).hasSingleBean(MockServerRestTemplateCustomizer.class));
}
@@ -63,6 +65,8 @@ class MockRestServiceServerAutoConfigurationTests {
}
@Test
@Deprecated(since = "4.2.0", forRemoval = true)
@SuppressWarnings("removal")
void backsOffWhenUserProvidesMockServerRestTemplateCustomizer() {
this.contextRunner.withBean("userMockServerRestTemplateCustomizer", MockServerRestTemplateCustomizer.class)
.run((context) -> assertThat(context).hasSingleBean(MockServerRestTemplateCustomizer.class)
@@ -34,8 +34,11 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
* Tests for {@link RestClientTest @RestClientTest} with no specific client.
*
* @author Phillip Webb
* @deprecated since 4.2.0 for removal in 4.4.0
*/
@RestClientTest
@Deprecated(since = "4.2.0", forRemoval = true)
@SuppressWarnings("removal")
class RestClientTestNoComponentIntegrationTests {
@Autowired
@@ -36,6 +36,7 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
* @author Scott Frederick
*/
@RestClientTest({ ExampleRestTemplateService.class, ExampleRestClientService.class })
@SuppressWarnings("removal")
class RestClientTestRestTemplateAndRestClientTogetherIntegrationTests {
@Autowired
@@ -31,8 +31,11 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
* Tests for {@link RestClientTest @RestClientTest} gets reset after test methods.
*
* @author Phillip Webb
* @deprecated since 4.2.0 for removal in 4.4.0
*/
@RestClientTest(ExampleRestTemplateService.class)
@Deprecated(since = "4.2.0", forRemoval = true)
@SuppressWarnings("removal")
class RestClientTestRestTemplateIntegrationTests {
@Autowired
@@ -32,8 +32,11 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
* Tests for {@link RestClientTest @RestClientTest} with two {@code RestTemplate} clients.
*
* @author Phillip Webb
* @deprecated since 4.2.0 for removal in 4.4.0
*/
@RestClientTest({ ExampleRestTemplateService.class, AnotherExampleRestTemplateService.class })
@Deprecated(since = "4.2.0", forRemoval = true)
@SuppressWarnings("removal")
class RestClientTestRestTemplateTwoComponentsIntegrationTests {
@Autowired
@@ -31,8 +31,11 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
* {@code RestTemplate}.
*
* @author Phillip Webb
* @deprecated since 4.2.0 for removal in 4.4.0
*/
@RestClientTest(ExampleRestTemplateService.class)
@Deprecated(since = "4.2.0", forRemoval = true)
@SuppressWarnings("removal")
class RestClientTestWithRestTemplateComponentIntegrationTests {
@Autowired
@@ -34,21 +34,21 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
* @author Andy Wilkinson
*/
@ClassPathExclusions("jackson-*.jar")
@RestClientTest(ExampleRestTemplateService.class)
@RestClientTest(ExampleRestClientService.class)
class RestClientTestWithoutJacksonIntegrationTests {
@Autowired
private MockRestServiceServer server;
@Autowired
private ExampleRestTemplateService client;
private ExampleRestClientService client;
@Test
void restClientTestCanBeUsedWhenJacksonIsNotOnTheClassPath() {
ClassLoader classLoader = getClass().getClassLoader();
assertThat(ClassUtils.isPresent("com.fasterxml.jackson.databind.Module", classLoader)).isFalse();
assertThat(ClassUtils.isPresent("tools.jackson.databind.JacksonModule", classLoader)).isFalse();
this.server.expect(requestTo("/test")).andRespond(withSuccess("hello", MediaType.TEXT_HTML));
this.server.expect(requestTo("https://example.com/test")).andRespond(withSuccess("hello", MediaType.TEXT_HTML));
assertThat(this.client.test()).isEqualTo("hello");
}
@@ -45,6 +45,7 @@ import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.web.client.ResponseErrorHandler;
import org.springframework.web.client.RestClient;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.DefaultUriBuilderFactory;
import org.springframework.web.util.UriTemplateHandler;
@@ -71,7 +72,10 @@ import org.springframework.web.util.UriTemplateHandler;
* @author Scott Frederick
* @author Yanming Zhou
* @since 4.0.0
* @deprecated since 4.2.0 for removal in 4.4.0 in favor of {@link RestClient.Builder}
*/
@Deprecated(since = "4.2.0", forRemoval = true)
@SuppressWarnings("removal")
public class RestTemplateBuilder {
private final HttpClientSettings clientSettings;
@@ -33,7 +33,10 @@ import org.springframework.http.client.ClientHttpRequestInitializer;
*
* @author Dmytro Nosan
* @author Ilya Lukyanovich
* @deprecated since 4.2.0 for removal in 4.4.0 with no replacement
*/
@Deprecated(since = "4.2.0", forRemoval = true)
@SuppressWarnings("removal")
class RestTemplateBuilderClientHttpRequestInitializer implements ClientHttpRequestInitializer {
private final @Nullable BasicAuthentication basicAuthentication;
@@ -24,8 +24,11 @@ import org.springframework.web.client.RestTemplate;
* @author Phillip Webb
* @since 4.0.0
* @see RestTemplateBuilder
* @deprecated since 4.2.0 for removal in 4.4.0 in favor of {@link RestClientCustomizer}
*/
@FunctionalInterface
@Deprecated(since = "4.2.0", forRemoval = true)
@SuppressWarnings("removal")
public interface RestTemplateCustomizer {
/**
@@ -30,8 +30,10 @@ import org.springframework.web.client.RestTemplate;
* @since 4.0.0
* @see RestTemplateBuilder
* @see ClientHttpRequestInitializer
* @deprecated since 4.2.0 for removal in 4.4.0 with no replacement
*/
@FunctionalInterface
@Deprecated(since = "4.2.0", forRemoval = true)
public interface RestTemplateRequestCustomizer<T extends ClientHttpRequest> {
/**
@@ -41,10 +41,14 @@ import org.springframework.web.client.RestTemplate;
* @author Stephane Nicoll
* @author Phillip Webb
* @since 4.0.0
* @deprecated since 4.2.0 for removal in 4.4.0 in favor of
* {@link RestClientAutoConfiguration}
*/
@AutoConfiguration(after = HttpClientAutoConfiguration.class)
@ConditionalOnClass({ RestTemplate.class, HttpMessageConverters.class })
@Conditional(NotReactiveWebApplicationCondition.class)
@Deprecated(since = "4.2.0", forRemoval = true)
@SuppressWarnings("removal")
public final class RestTemplateAutoConfiguration {
@Bean
@@ -41,7 +41,11 @@ import org.springframework.util.ObjectUtils;
*
* @author Stephane Nicoll
* @since 4.0.0
* @deprecated since 4.2.0 for removal in 4.4.0 in favor of
* {@link RestClientBuilderConfigurer}
*/
@Deprecated(since = "4.2.0", forRemoval = true)
@SuppressWarnings("removal")
public final class RestTemplateBuilderConfigurer {
private @Nullable ClientHttpRequestFactoryBuilder<?> requestFactoryBuilder;
@@ -36,12 +36,16 @@ import org.springframework.web.client.RestTemplate;
*
* @author Brian Clozel
* @since 4.0.0
* @deprecated since 4.2.0 for removal in 4.4.0 in favor of
* {@link RestClientObservationAutoConfiguration}
*/
@AutoConfiguration
@ConditionalOnClass({ RestTemplate.class, ObservationRestTemplateCustomizer.class, ObservationRegistry.class,
ObservationProperties.class })
@ConditionalOnBean({ ObservationRegistry.class, RestTemplateBuilder.class })
@EnableConfigurationProperties(ObservationProperties.class)
@Deprecated(since = "4.2.0", forRemoval = true)
@SuppressWarnings("removal")
public final class RestTemplateObservationAutoConfiguration {
@Bean
@@ -28,7 +28,11 @@ import org.springframework.web.client.RestTemplate;
*
* @author Brian Clozel
* @since 4.0.0
* @deprecated since 4.2.0 for removal in 4.4.0 in favor of
* {@link ObservationRestClientCustomizer}
*/
@Deprecated(since = "4.2.0", forRemoval = true)
@SuppressWarnings("removal")
public class ObservationRestTemplateCustomizer implements RestTemplateCustomizer {
private final ObservationRegistry observationRegistry;
@@ -31,7 +31,10 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
* Tests for building a {@link RestClient} from a {@link RestTemplateBuilder}.
*
* @author Scott Frederick
* @deprecated since 4.2.0 for removal in 4.4.0
*/
@Deprecated(since = "4.2.0", forRemoval = true)
@SuppressWarnings("removal")
class RestClientWithRestTemplateBuilderTests {
@Test
@@ -32,7 +32,10 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
* Tests for building a {@link RestClient} from a {@link RestTemplate}.
*
* @author Scott Frederick
* @deprecated since 4.2.0 for removal in 4.4.0
*/
@Deprecated(since = "4.2.0", forRemoval = true)
@SuppressWarnings("removal")
class RestClientWithRestTemplateTests {
@Test
@@ -41,7 +41,10 @@ import static org.mockito.Mockito.mock;
* @author Dmytro Nosan
* @author Ilya Lukyanovich
* @author Phillip Webb
* @deprecated since 4.2.0 for removal in 4.4.0
*/
@Deprecated(since = "4.2.0", forRemoval = true)
@SuppressWarnings("removal")
class RestTemplateBuilderClientHttpRequestInitializerTests {
private final MockClientHttpRequest request = new MockClientHttpRequest();
@@ -80,8 +80,11 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
* @author Ilya Lukyanovich
* @author Brian Clozel
* @author Yanming Zhou
* @deprecated since 4.2.0 for removal in 4.4.0
*/
@ExtendWith(MockitoExtension.class)
@Deprecated(since = "4.2.0", forRemoval = true)
@SuppressWarnings("removal")
class RestTemplateBuilderTests {
private final RestTemplateBuilder builder = new RestTemplateBuilder();
@@ -59,7 +59,10 @@ import static org.mockito.Mockito.mock;
*
* @author Stephane Nicoll
* @author Phillip Webb
* @deprecated since 4.2.0 for removal in 4.4.0
*/
@Deprecated(since = "4.2.0", forRemoval = true)
@SuppressWarnings("removal")
class RestTemplateAutoConfigurationTests {
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
@@ -49,8 +49,11 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
* Tests for {@link RestTemplateObservationAutoConfiguration}.
*
* @author Brian Clozel
* @deprecated since 4.2.0 for removal in 4.4.0
*/
@ExtendWith(OutputCaptureExtension.class)
@Deprecated(since = "4.2.0", forRemoval = true)
@SuppressWarnings("removal")
class RestTemplateObservationAutoConfigurationTests {
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
@@ -41,9 +41,12 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
*
* @author Brian Clozel
* @author Andy Wilkinson
* @deprecated since 4.2.0 for removal in 4.4.0
*/
@ExtendWith(OutputCaptureExtension.class)
@ClassPathExclusions("micrometer-core-*.jar")
@Deprecated(since = "4.2.0", forRemoval = true)
@SuppressWarnings("removal")
class RestTemplateObservationAutoConfigurationWithoutMetricsTests {
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
@@ -29,7 +29,10 @@ import static org.assertj.core.api.Assertions.assertThat;
* Tests for {@link ObservationRestTemplateCustomizer}.
*
* @author Brian Clozel
* @deprecated since 4.2.0 for removal in 4.4.0
*/
@Deprecated(since = "4.2.0", forRemoval = true)
@SuppressWarnings("removal")
class ObservationRestTemplateCustomizerTests {
private static final String TEST_METRIC_NAME = "http.test.metric.name";
@@ -91,6 +91,7 @@ import org.springframework.web.util.UriTemplateHandler;
* @author Yanming Zhou
* @since 4.0.0
*/
@SuppressWarnings("removal")
public class TestRestTemplate {
private final RestTemplateBuilder builder;
@@ -34,6 +34,7 @@ import org.springframework.context.annotation.Bean;
* @see AutoConfigureTestRestTemplate
*/
@AutoConfiguration
@SuppressWarnings("removal")
final class TestRestTemplateTestAutoConfiguration {
@Bean(name = "org.springframework.boot.resttestclient.TestRestTemplate")
@@ -81,6 +81,7 @@ import static org.mockito.Mockito.mock;
* @author Kristine Jetzke
* @author Yanming Zhou
*/
@SuppressWarnings("removal")
class TestRestTemplateTests {
@Test
@@ -44,6 +44,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles("cors")
@AutoConfigureTestRestTemplate
@SuppressWarnings("removal")
class CorsSampleActuatorApplicationTests {
private TestRestTemplate testRestTemplate;
@@ -35,6 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "spring.web.error.include-message=always" })
@AutoConfigureTestRestTemplate
@SuppressWarnings("removal")
class SampleActuatorExtensionApplicationTests {
@Autowired
@@ -44,6 +44,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles("cors")
@AutoConfigureTestRestTemplate
@SuppressWarnings("removal")
class CorsSampleActuatorApplicationTests {
private TestRestTemplate testRestTemplate;
@@ -62,6 +62,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@ExtendWith(OutputCaptureExtension.class)
@AutoConfigureTestRestTemplate
@SuppressWarnings("removal")
class SampleTomcatApplicationTests {
@Autowired
@@ -43,6 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat;
/**
* Abstract class for deployment tests.
*/
@SuppressWarnings("removal")
abstract class AbstractDeploymentTests {
protected static final int DEFAULT_PORT = 8080;