Class RestTemplateBuilder
java.lang.Object
org.springframework.boot.restclient.RestTemplateBuilder
Deprecated, for removal: This API element is subject to removal in a future version.
Builder that can be used to configure and create a
RestTemplate. Provides
convenience methods to register converters, error handlers and
UriTemplateHandlers.
By default, the built RestTemplate will attempt to use the most suitable
ClientHttpRequestFactory, call detectRequestFactory(false) if you prefer to keep the default. In a typical
auto-configured Spring Boot application this builder is available as a bean and can be
injected whenever a RestTemplate is needed.
- Since:
- 4.0.0
- Author:
- Stephane Nicoll, Phillip Webb, Andy Wilkinson, Brian Clozel, Dmytro Nosan, Kevin Strijbos, Ilya Lukyanovich, Scott Frederick, Yanming Zhou
-
Constructor Summary
ConstructorsConstructorDescriptionRestTemplateBuilder(RestTemplateCustomizer... customizers) Deprecated, for removal: This API element is subject to removal in a future version.Create a newRestTemplateBuilderinstance. -
Method Summary
Modifier and TypeMethodDescriptionadditionalCustomizers(Collection<? extends RestTemplateCustomizer> customizers) Deprecated, for removal: This API element is subject to removal in a future version.AddRestTemplateCustomizersthat should be applied to theRestTemplate.additionalCustomizers(RestTemplateCustomizer... customizers) Deprecated, for removal: This API element is subject to removal in a future version.AddRestTemplateCustomizersthat should be applied to theRestTemplate.additionalInterceptors(Collection<? extends ClientHttpRequestInterceptor> interceptors) Deprecated, for removal: This API element is subject to removal in a future version.Add additionalClientHttpRequestInterceptorsthat should be used with theRestTemplate.additionalInterceptors(ClientHttpRequestInterceptor... interceptors) Deprecated, for removal: This API element is subject to removal in a future version.Add additionalClientHttpRequestInterceptorsthat should be used with theRestTemplate.additionalMessageConverters(Collection<? extends HttpMessageConverter<?>> messageConverters) Deprecated, for removal: This API element is subject to removal in a future version.Add additionalHttpMessageConvertersthat should be used with theRestTemplate.additionalMessageConverters(HttpMessageConverter<?>... messageConverters) Deprecated, for removal: This API element is subject to removal in a future version.Add additionalHttpMessageConvertersthat should be used with theRestTemplate.additionalRequestCustomizers(Collection<? extends RestTemplateRequestCustomizer<?>> requestCustomizers) Deprecated, for removal: This API element is subject to removal in a future version.Add theRestTemplateRequestCustomizersthat should be applied to theClientHttpRequest.additionalRequestCustomizers(RestTemplateRequestCustomizer<?>... requestCustomizers) Deprecated, for removal: This API element is subject to removal in a future version.Add theRestTemplateRequestCustomizersthat should be applied to theClientHttpRequest.Deprecated, for removal: This API element is subject to removal in a future version.Set a base URL template that should be applied to each request that starts with'/'.basicAuthentication(String username, String password) Deprecated, for removal: This API element is subject to removal in a future version.Add HTTP Basic Authentication to requests with the given username/password pair, unless a custom Authorization header has been set before.basicAuthentication(String username, String password, @Nullable Charset charset) Deprecated, for removal: This API element is subject to removal in a future version.Add HTTP Basic Authentication to requests with the given username/password pair, unless a custom Authorization header has been set before.build()Deprecated, for removal: This API element is subject to removal in a future version.Build a newRestTemplateinstance and configure it using this builder.<T extends RestTemplate>
TDeprecated, for removal: This API element is subject to removal in a future version.Build a newRestTemplateinstance of the specified type and configure it using this builder.@Nullable ClientHttpRequestFactoryDeprecated, for removal: This API element is subject to removal in a future version.Build a newClientHttpRequestFactoryinstance using the settings of this builder.clientSettings(UnaryOperator<HttpClientSettings> clientSettingsCustomizer) Deprecated, for removal: This API element is subject to removal in a future version.Update theHttpClientSettingsusing the given customizer.clientSettings(HttpClientSettings clientSettings) Deprecated, for removal: This API element is subject to removal in a future version.Sets theHttpClientSettings.<T extends RestTemplate>
Tconfigure(T restTemplate) Deprecated, for removal: This API element is subject to removal in a future version.Configure the providedRestTemplateinstance using this builder.connectTimeout(Duration connectTimeout) Deprecated, for removal: This API element is subject to removal in a future version.Sets the connection timeout on the underlyingClientHttpRequestFactory.cookieHandling(HttpCookieHandling cookieHandling) Deprecated, for removal: This API element is subject to removal in a future version.Sets the cookie handling strategy on the underlyingClientHttpRequestFactory.customizers(Collection<? extends RestTemplateCustomizer> customizers) Deprecated, for removal: This API element is subject to removal in a future version.Set theRestTemplateCustomizersthat should be applied to theRestTemplate.customizers(RestTemplateCustomizer... customizers) Deprecated, for removal: This API element is subject to removal in a future version.Set theRestTemplateCustomizersthat should be applied to theRestTemplate.defaultHeader(String name, String... values) Deprecated, for removal: This API element is subject to removal in a future version.Add a default header that will be set if not already present on the outgoingClientHttpRequest.Deprecated, for removal: This API element is subject to removal in a future version.Set theHttpMessageConvertersthat should be used with theRestTemplateto the default set.detectRequestFactory(boolean detectRequestFactory) Deprecated, for removal: This API element is subject to removal in a future version.Set if theClientHttpRequestFactoryshould be detected based on the classpath.errorHandler(ResponseErrorHandler errorHandler) Deprecated, for removal: This API element is subject to removal in a future version.Set theResponseErrorHandlerthat should be used with theRestTemplate.interceptors(Collection<ClientHttpRequestInterceptor> interceptors) Deprecated, for removal: This API element is subject to removal in a future version.Set theClientHttpRequestInterceptorsthat should be used with theRestTemplate.interceptors(ClientHttpRequestInterceptor... interceptors) Deprecated, for removal: This API element is subject to removal in a future version.Set theClientHttpRequestInterceptorsthat should be used with theRestTemplate.messageConverters(Iterable<? extends HttpMessageConverter<?>> messageConverters) Deprecated, for removal: This API element is subject to removal in a future version.Set theHttpMessageConvertersthat should be used with theRestTemplate.messageConverters(HttpMessageConverter<?>... messageConverters) Deprecated, for removal: This API element is subject to removal in a future version.Set theHttpMessageConvertersthat should be used with theRestTemplate.readTimeout(Duration readTimeout) Deprecated, for removal: This API element is subject to removal in a future version.Sets the read timeout on the underlyingClientHttpRequestFactory.redirects(HttpRedirects redirects) Deprecated, for removal: This API element is subject to removal in a future version.Sets the redirect strategy on the underlyingClientHttpRequestFactory.requestCustomizers(Collection<? extends RestTemplateRequestCustomizer<?>> requestCustomizers) Deprecated, for removal: This API element is subject to removal in a future version.Set theRestTemplateRequestCustomizersthat should be applied to theClientHttpRequest.requestCustomizers(RestTemplateRequestCustomizer<?>... requestCustomizers) Deprecated, for removal: This API element is subject to removal in a future version.Set theRestTemplateRequestCustomizersthat should be applied to theClientHttpRequest.requestFactory(Class<? extends ClientHttpRequestFactory> requestFactoryType) Deprecated, for removal: This API element is subject to removal in a future version.Set theClientHttpRequestFactoryclass that should be used with theRestTemplate.requestFactory(Supplier<ClientHttpRequestFactory> requestFactorySupplier) Deprecated, for removal: This API element is subject to removal in a future version.Set theSupplierofClientHttpRequestFactorythat should be called each time webuild()a newRestTemplateinstance.@Nullable ClientHttpRequestFactoryBuilder<?> Deprecated, for removal: This API element is subject to removal in a future version.Return aClientHttpRequestFactoryBuilderinstance using the settings of this builder.requestFactoryBuilder(ClientHttpRequestFactoryBuilder<?> requestFactoryBuilder) Deprecated, for removal: This API element is subject to removal in a future version.Set theClientHttpRequestFactoryBuilderthat should be used each time webuild()a newRestTemplateinstance.Deprecated, for removal: This API element is subject to removal in a future version.since 4.1.0 for removal in 4.3.0 in favor ofbaseUri(String)Deprecated, for removal: This API element is subject to removal in a future version.Sets the SSL bundle on the underlyingClientHttpRequestFactory.uriTemplateHandler(UriTemplateHandler uriTemplateHandler) Deprecated, for removal: This API element is subject to removal in a future version.Set theUriTemplateHandlerthat should be used with theRestTemplate.
-
Constructor Details
-
RestTemplateBuilder
Deprecated, for removal: This API element is subject to removal in a future version.Create a newRestTemplateBuilderinstance.- Parameters:
customizers- anyRestTemplateCustomizersthat should be applied when theRestTemplateis built
-
-
Method Details
-
baseUri
Deprecated, for removal: This API element is subject to removal in a future version.Set a base URL template that should be applied to each request that starts with'/'. The base URL will only apply whenStringvariants of theRestTemplatemethods are used for specifying the request URL.This is a specialization of
uriTemplateHandler(UriTemplateHandler)and will override any previously configured uri template handler.- Parameters:
baseUri- the base URI- Returns:
- a new builder instance
- Since:
- 4.1.0
-
detectRequestFactory
Deprecated, for removal: This API element is subject to removal in a future version.Set if theClientHttpRequestFactoryshould be detected based on the classpath. Default iftrue.- Parameters:
detectRequestFactory- if theClientHttpRequestFactoryshould be detected- Returns:
- a new builder instance
-
rootUri
@Deprecated(forRemoval=true, since="4.1.0") public RestTemplateBuilder rootUri(@Nullable String rootUri) Deprecated, for removal: This API element is subject to removal in a future version.since 4.1.0 for removal in 4.3.0 in favor ofbaseUri(String)Set a root URL that should be applied to each request that starts with'/'. The root URL will only apply whenStringvariants of theRestTemplatemethods are used for specifying the request URL.- Parameters:
rootUri- the root URI ornull- Returns:
- a new builder instance
-
messageConverters
Deprecated, for removal: This API element is subject to removal in a future version.Set theHttpMessageConvertersthat should be used with theRestTemplate. Setting this value will replace any previously configured converters and any converters configured on the builder will replace RestTemplate's default converters.- Parameters:
messageConverters- the converters to set- Returns:
- a new builder instance
- See Also:
-
messageConverters
public RestTemplateBuilder messageConverters(Iterable<? extends HttpMessageConverter<?>> messageConverters) Deprecated, for removal: This API element is subject to removal in a future version.Set theHttpMessageConvertersthat should be used with theRestTemplate. Setting this value will replace any previously configured converters and any converters configured on the builder will replace RestTemplate's default converters.- Parameters:
messageConverters- the converters to set- Returns:
- a new builder instance
- See Also:
-
additionalMessageConverters
public RestTemplateBuilder additionalMessageConverters(HttpMessageConverter<?>... messageConverters) Deprecated, for removal: This API element is subject to removal in a future version.Add additionalHttpMessageConvertersthat should be used with theRestTemplate. Any converters configured on the builder will replace RestTemplate's default converters.- Parameters:
messageConverters- the converters to add- Returns:
- a new builder instance
- See Also:
-
additionalMessageConverters
public RestTemplateBuilder additionalMessageConverters(Collection<? extends HttpMessageConverter<?>> messageConverters) Deprecated, for removal: This API element is subject to removal in a future version.Add additionalHttpMessageConvertersthat should be used with theRestTemplate. Any converters configured on the builder will replace RestTemplate's default converters.- Parameters:
messageConverters- the converters to add- Returns:
- a new builder instance
- See Also:
-
defaultMessageConverters
Deprecated, for removal: This API element is subject to removal in a future version.Set theHttpMessageConvertersthat should be used with theRestTemplateto the default set. Calling this method will replace any previously defined converters.- Returns:
- a new builder instance
- See Also:
-
interceptors
Deprecated, for removal: This API element is subject to removal in a future version.Set theClientHttpRequestInterceptorsthat should be used with theRestTemplate. Setting this value will replace any previously defined interceptors.- Parameters:
interceptors- the interceptors to set- Returns:
- a new builder instance
- See Also:
-
interceptors
Deprecated, for removal: This API element is subject to removal in a future version.Set theClientHttpRequestInterceptorsthat should be used with theRestTemplate. Setting this value will replace any previously defined interceptors.- Parameters:
interceptors- the interceptors to set- Returns:
- a new builder instance
- See Also:
-
additionalInterceptors
Deprecated, for removal: This API element is subject to removal in a future version.Add additionalClientHttpRequestInterceptorsthat should be used with theRestTemplate.- Parameters:
interceptors- the interceptors to add- Returns:
- a new builder instance
- See Also:
-
additionalInterceptors
public RestTemplateBuilder additionalInterceptors(Collection<? extends ClientHttpRequestInterceptor> interceptors) Deprecated, for removal: This API element is subject to removal in a future version.Add additionalClientHttpRequestInterceptorsthat should be used with theRestTemplate.- Parameters:
interceptors- the interceptors to add- Returns:
- a new builder instance
- See Also:
-
requestFactory
public RestTemplateBuilder requestFactory(Class<? extends ClientHttpRequestFactory> requestFactoryType) Deprecated, for removal: This API element is subject to removal in a future version.Set theClientHttpRequestFactoryclass that should be used with theRestTemplate.- Parameters:
requestFactoryType- the request factory type to use- Returns:
- a new builder instance
- See Also:
-
requestFactory
public RestTemplateBuilder requestFactory(Supplier<ClientHttpRequestFactory> requestFactorySupplier) Deprecated, for removal: This API element is subject to removal in a future version.Set theSupplierofClientHttpRequestFactorythat should be called each time webuild()a newRestTemplateinstance.- Parameters:
requestFactorySupplier- the supplier for the request factory- Returns:
- a new builder instance
- See Also:
-
requestFactoryBuilder
public RestTemplateBuilder requestFactoryBuilder(ClientHttpRequestFactoryBuilder<?> requestFactoryBuilder) Deprecated, for removal: This API element is subject to removal in a future version.Set theClientHttpRequestFactoryBuilderthat should be used each time webuild()a newRestTemplateinstance.- Parameters:
requestFactoryBuilder- theClientHttpRequestFactoryBuilderto use- Returns:
- a new builder instance
- See Also:
-
uriTemplateHandler
Deprecated, for removal: This API element is subject to removal in a future version.Set theUriTemplateHandlerthat should be used with theRestTemplate.This method will override any
baseUri(String)previously set.- Parameters:
uriTemplateHandler- the URI template handler to use- Returns:
- a new builder instance
-
errorHandler
Deprecated, for removal: This API element is subject to removal in a future version.Set theResponseErrorHandlerthat should be used with theRestTemplate.- Parameters:
errorHandler- the error handler to use- Returns:
- a new builder instance
-
basicAuthentication
Deprecated, for removal: This API element is subject to removal in a future version.Add HTTP Basic Authentication to requests with the given username/password pair, unless a custom Authorization header has been set before.- Parameters:
username- the user namepassword- the password- Returns:
- a new builder instance
- See Also:
-
basicAuthentication
public RestTemplateBuilder basicAuthentication(String username, String password, @Nullable Charset charset) Deprecated, for removal: This API element is subject to removal in a future version.Add HTTP Basic Authentication to requests with the given username/password pair, unless a custom Authorization header has been set before.- Parameters:
username- the user namepassword- the passwordcharset- the charset to use- Returns:
- a new builder instance
-
defaultHeader
Deprecated, for removal: This API element is subject to removal in a future version.Add a default header that will be set if not already present on the outgoingClientHttpRequest.- Parameters:
name- the name of the headervalues- the header values- Returns:
- a new builder instance
-
clientSettings
Deprecated, for removal: This API element is subject to removal in a future version.Sets theHttpClientSettings. This will replace any previously setconnectTimeout,readTimeoutandsslBundlevalues.- Parameters:
clientSettings- the client settings- Returns:
- a new builder instance
-
clientSettings
public RestTemplateBuilder clientSettings(UnaryOperator<HttpClientSettings> clientSettingsCustomizer) Deprecated, for removal: This API element is subject to removal in a future version.Update theHttpClientSettingsusing the given customizer.- Parameters:
clientSettingsCustomizer- aUnaryOperatorto update client factory settings- Returns:
- a new builder instance
-
connectTimeout
Deprecated, for removal: This API element is subject to removal in a future version.Sets the connection timeout on the underlyingClientHttpRequestFactory.- Parameters:
connectTimeout- the connection timeout- Returns:
- a new builder instance.
-
readTimeout
Deprecated, for removal: This API element is subject to removal in a future version.Sets the read timeout on the underlyingClientHttpRequestFactory.- Parameters:
readTimeout- the read timeout- Returns:
- a new builder instance.
-
cookieHandling
Deprecated, for removal: This API element is subject to removal in a future version.Sets the cookie handling strategy on the underlyingClientHttpRequestFactory.- Parameters:
cookieHandling- the cookie handling strategy- Returns:
- a new builder instance.
- Since:
- 4.1.0
-
redirects
Deprecated, for removal: This API element is subject to removal in a future version.Sets the redirect strategy on the underlyingClientHttpRequestFactory.- Parameters:
redirects- the redirect strategy- Returns:
- a new builder instance.
-
sslBundle
Deprecated, for removal: This API element is subject to removal in a future version.Sets the SSL bundle on the underlyingClientHttpRequestFactory.- Parameters:
sslBundle- the SSL bundle- Returns:
- a new builder instance
-
customizers
Deprecated, for removal: This API element is subject to removal in a future version.Set theRestTemplateCustomizersthat should be applied to theRestTemplate. Customizers are applied in the order that they were added after builder configuration has been applied. Setting this value will replace any previously configured customizers.- Parameters:
customizers- the customizers to set- Returns:
- a new builder instance
- See Also:
-
customizers
Deprecated, for removal: This API element is subject to removal in a future version.Set theRestTemplateCustomizersthat should be applied to theRestTemplate. Customizers are applied in the order that they were added after builder configuration has been applied. Setting this value will replace any previously configured customizers.- Parameters:
customizers- the customizers to set- Returns:
- a new builder instance
- See Also:
-
additionalCustomizers
Deprecated, for removal: This API element is subject to removal in a future version.AddRestTemplateCustomizersthat should be applied to theRestTemplate. Customizers are applied in the order that they were added after builder configuration has been applied.- Parameters:
customizers- the customizers to add- Returns:
- a new builder instance
- See Also:
-
additionalCustomizers
public RestTemplateBuilder additionalCustomizers(Collection<? extends RestTemplateCustomizer> customizers) Deprecated, for removal: This API element is subject to removal in a future version.AddRestTemplateCustomizersthat should be applied to theRestTemplate. Customizers are applied in the order that they were added after builder configuration has been applied.- Parameters:
customizers- the customizers to add- Returns:
- a new builder instance
- See Also:
-
requestCustomizers
public RestTemplateBuilder requestCustomizers(RestTemplateRequestCustomizer<?>... requestCustomizers) Deprecated, for removal: This API element is subject to removal in a future version.Set theRestTemplateRequestCustomizersthat should be applied to theClientHttpRequest. Customizers are applied in the order that they were added. Setting this value will replace any previously configured request customizers.- Parameters:
requestCustomizers- the request customizers to set- Returns:
- a new builder instance
- See Also:
-
requestCustomizers
public RestTemplateBuilder requestCustomizers(Collection<? extends RestTemplateRequestCustomizer<?>> requestCustomizers) Deprecated, for removal: This API element is subject to removal in a future version.Set theRestTemplateRequestCustomizersthat should be applied to theClientHttpRequest. Customizers are applied in the order that they were added. Setting this value will replace any previously configured request customizers.- Parameters:
requestCustomizers- the request customizers to set- Returns:
- a new builder instance
- See Also:
-
additionalRequestCustomizers
public RestTemplateBuilder additionalRequestCustomizers(RestTemplateRequestCustomizer<?>... requestCustomizers) Deprecated, for removal: This API element is subject to removal in a future version.Add theRestTemplateRequestCustomizersthat should be applied to theClientHttpRequest. Customizers are applied in the order that they were added.- Parameters:
requestCustomizers- the request customizers to add- Returns:
- a new builder instance
- See Also:
-
additionalRequestCustomizers
public RestTemplateBuilder additionalRequestCustomizers(Collection<? extends RestTemplateRequestCustomizer<?>> requestCustomizers) Deprecated, for removal: This API element is subject to removal in a future version.Add theRestTemplateRequestCustomizersthat should be applied to theClientHttpRequest. Customizers are applied in the order that they were added.- Parameters:
requestCustomizers- the request customizers to add- Returns:
- a new builder instance
- See Also:
-
build
Deprecated, for removal: This API element is subject to removal in a future version.Build a newRestTemplateinstance and configure it using this builder.- Returns:
- a configured
RestTemplateinstance. - See Also:
-
build
Deprecated, for removal: This API element is subject to removal in a future version.Build a newRestTemplateinstance of the specified type and configure it using this builder.- Type Parameters:
T- the type of rest template- Parameters:
restTemplateClass- the template type to create- Returns:
- a configured
RestTemplateinstance. - See Also:
-
configure
Deprecated, for removal: This API element is subject to removal in a future version.Configure the providedRestTemplateinstance using this builder.- Type Parameters:
T- the type of rest template- Parameters:
restTemplate- theRestTemplateto configure- Returns:
- the rest template instance
- See Also:
-
buildRequestFactory
Deprecated, for removal: This API element is subject to removal in a future version.Build a newClientHttpRequestFactoryinstance using the settings of this builder.- Returns:
- a
ClientHttpRequestFactoryornull
-
requestFactoryBuilder
Deprecated, for removal: This API element is subject to removal in a future version.Return aClientHttpRequestFactoryBuilderinstance using the settings of this builder.- Returns:
- a
ClientHttpRequestFactoryBuilderornull
-
RestClient.Builder