public class RestTemplateBuilder extends Object
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.
| Constructor and Description | 
|---|
| RestTemplateBuilder(RestTemplateCustomizer... customizers)Create a new  RestTemplateBuilderinstance. | 
| Modifier and Type | Method and Description | 
|---|---|
| RestTemplateBuilder | additionalCustomizers(Collection<? extends RestTemplateCustomizer> customizers)Add  RestTemplateCustomizersthat should be applied
 to theRestTemplate. | 
| RestTemplateBuilder | additionalCustomizers(RestTemplateCustomizer... restTemplateCustomizers)Add  RestTemplateCustomizersthat should be applied
 to theRestTemplate. | 
| RestTemplateBuilder | additionalInterceptors(org.springframework.http.client.ClientHttpRequestInterceptor... interceptors)Add additional  ClientHttpRequestInterceptorsthat should be used with theRestTemplate. | 
| RestTemplateBuilder | additionalInterceptors(Collection<? extends org.springframework.http.client.ClientHttpRequestInterceptor> interceptors)Add additional  ClientHttpRequestInterceptorsthat should be used with theRestTemplate. | 
| RestTemplateBuilder | additionalMessageConverters(Collection<? extends org.springframework.http.converter.HttpMessageConverter<?>> messageConverters)Add additional  HttpMessageConvertersthat should be
 used with theRestTemplate. | 
| RestTemplateBuilder | additionalMessageConverters(org.springframework.http.converter.HttpMessageConverter<?>... messageConverters)Add additional  HttpMessageConvertersthat should be
 used with theRestTemplate. | 
| RestTemplateBuilder | basicAuthentication(String username,
                   String password)Add HTTP basic authentication to requests. | 
| RestTemplateBuilder | basicAuthorization(String username,
                  String password)Deprecated. 
 since 2.1.0 in favor of
  basicAuthentication(String username, String password) | 
| org.springframework.web.client.RestTemplate | build()Build a new  RestTemplateinstance and configure it using this builder. | 
| <T extends org.springframework.web.client.RestTemplate> | build(Class<T> restTemplateClass)Build a new  RestTemplateinstance of the specified type and configure it
 using this builder. | 
| <T extends org.springframework.web.client.RestTemplate> | configure(T restTemplate)Configure the provided  RestTemplateinstance using this builder. | 
| RestTemplateBuilder | customizers(Collection<? extends RestTemplateCustomizer> restTemplateCustomizers)Set the  RestTemplateCustomizersthat should be
 applied to theRestTemplate. | 
| RestTemplateBuilder | customizers(RestTemplateCustomizer... restTemplateCustomizers)Set the  RestTemplateCustomizersthat should be
 applied to theRestTemplate. | 
| RestTemplateBuilder | defaultMessageConverters()Set the  HttpMessageConvertersthat should be used with
 theRestTemplateto the default set. | 
| RestTemplateBuilder | detectRequestFactory(boolean detectRequestFactory)Set if the  ClientHttpRequestFactoryshould be detected based on the
 classpath. | 
| RestTemplateBuilder | errorHandler(org.springframework.web.client.ResponseErrorHandler errorHandler)Set the  ResponseErrorHandlerthat should be used with theRestTemplate. | 
| RestTemplateBuilder | interceptors(org.springframework.http.client.ClientHttpRequestInterceptor... interceptors)Set the  ClientHttpRequestInterceptorsthat
 should be used with theRestTemplate. | 
| RestTemplateBuilder | interceptors(Collection<org.springframework.http.client.ClientHttpRequestInterceptor> interceptors)Set the  ClientHttpRequestInterceptorsthat
 should be used with theRestTemplate. | 
| RestTemplateBuilder | messageConverters(Collection<? extends org.springframework.http.converter.HttpMessageConverter<?>> messageConverters)Set the  HttpMessageConvertersthat should be used with
 theRestTemplate. | 
| RestTemplateBuilder | messageConverters(org.springframework.http.converter.HttpMessageConverter<?>... messageConverters)Set the  HttpMessageConvertersthat should be used with
 theRestTemplate. | 
| RestTemplateBuilder | requestFactory(Class<? extends org.springframework.http.client.ClientHttpRequestFactory> requestFactory)Set the  ClientHttpRequestFactoryclass that should be used with theRestTemplate. | 
| RestTemplateBuilder | requestFactory(Supplier<org.springframework.http.client.ClientHttpRequestFactory> requestFactorySupplier)Set the  SupplierofClientHttpRequestFactorythat should be called
 each time webuild()a newRestTemplateinstance. | 
| RestTemplateBuilder | rootUri(String rootUri)Set a root URL that should be applied to each request that starts with  '/'. | 
| RestTemplateBuilder | setConnectTimeout(Duration connectTimeout)Sets the connection timeout on the underlying  ClientHttpRequestFactory. | 
| RestTemplateBuilder | setConnectTimeout(int connectTimeout)Deprecated. 
 since 2.1.0 in favor of  setConnectTimeout(Duration) | 
| RestTemplateBuilder | setReadTimeout(Duration readTimeout)Sets the read timeout on the underlying  ClientHttpRequestFactory. | 
| RestTemplateBuilder | setReadTimeout(int readTimeout)Deprecated. 
 since 2.1.0 in favor of  setReadTimeout(Duration) | 
| RestTemplateBuilder | uriTemplateHandler(org.springframework.web.util.UriTemplateHandler uriTemplateHandler)Set the  UriTemplateHandlerthat should be used with theRestTemplate. | 
public RestTemplateBuilder(RestTemplateCustomizer... customizers)
RestTemplateBuilder instance.customizers - any RestTemplateCustomizers that
 should be applied when the RestTemplate is builtpublic RestTemplateBuilder detectRequestFactory(boolean detectRequestFactory)
ClientHttpRequestFactory should be detected based on the
 classpath. Default if true.detectRequestFactory - if the ClientHttpRequestFactory should be
 detectedpublic RestTemplateBuilder rootUri(String rootUri)
'/'.
 Since this works by adding a UriTemplateHandler to the
 RestTemplate, the root URL will only apply when String variants of
 the RestTemplate methods are used for specifying the request URL. See
 RootUriTemplateHandler for details.rootUri - the root URI or nullpublic RestTemplateBuilder messageConverters(org.springframework.http.converter.HttpMessageConverter<?>... messageConverters)
HttpMessageConverters that should be used with
 the RestTemplate. Setting this value will replace any previously configured
 converters and any converters configured on the builder will replace RestTemplate's
 default converters.messageConverters - the converters to setadditionalMessageConverters(HttpMessageConverter...)public RestTemplateBuilder messageConverters(Collection<? extends org.springframework.http.converter.HttpMessageConverter<?>> messageConverters)
HttpMessageConverters that should be used with
 the RestTemplate. Setting this value will replace any previously configured
 converters and any converters configured on the builder will replace RestTemplate's
 default converters.messageConverters - the converters to setadditionalMessageConverters(HttpMessageConverter...)public RestTemplateBuilder additionalMessageConverters(org.springframework.http.converter.HttpMessageConverter<?>... messageConverters)
HttpMessageConverters that should be
 used with the RestTemplate. Any converters configured on the builder will
 replace RestTemplate's default converters.messageConverters - the converters to addmessageConverters(HttpMessageConverter...)public RestTemplateBuilder additionalMessageConverters(Collection<? extends org.springframework.http.converter.HttpMessageConverter<?>> messageConverters)
HttpMessageConverters that should be
 used with the RestTemplate. Any converters configured on the builder will
 replace RestTemplate's default converters.messageConverters - the converters to addmessageConverters(HttpMessageConverter...)public RestTemplateBuilder defaultMessageConverters()
HttpMessageConverters that should be used with
 the RestTemplate to the default set. Calling this method will replace any
 previously defined converters.messageConverters(HttpMessageConverter...)public RestTemplateBuilder interceptors(org.springframework.http.client.ClientHttpRequestInterceptor... interceptors)
ClientHttpRequestInterceptors that
 should be used with the RestTemplate. Setting this value will replace any
 previously defined interceptors.interceptors - the interceptors to setadditionalInterceptors(ClientHttpRequestInterceptor...)public RestTemplateBuilder interceptors(Collection<org.springframework.http.client.ClientHttpRequestInterceptor> interceptors)
ClientHttpRequestInterceptors that
 should be used with the RestTemplate. Setting this value will replace any
 previously defined interceptors.interceptors - the interceptors to setadditionalInterceptors(ClientHttpRequestInterceptor...)public RestTemplateBuilder additionalInterceptors(org.springframework.http.client.ClientHttpRequestInterceptor... interceptors)
ClientHttpRequestInterceptors
 that should be used with the RestTemplate.interceptors - the interceptors to addinterceptors(ClientHttpRequestInterceptor...)public RestTemplateBuilder additionalInterceptors(Collection<? extends org.springframework.http.client.ClientHttpRequestInterceptor> interceptors)
ClientHttpRequestInterceptors
 that should be used with the RestTemplate.interceptors - the interceptors to addinterceptors(ClientHttpRequestInterceptor...)public RestTemplateBuilder requestFactory(Class<? extends org.springframework.http.client.ClientHttpRequestFactory> requestFactory)
ClientHttpRequestFactory class that should be used with the
 RestTemplate.requestFactory - the request factory to usepublic RestTemplateBuilder requestFactory(Supplier<org.springframework.http.client.ClientHttpRequestFactory> requestFactorySupplier)
Supplier of ClientHttpRequestFactory that should be called
 each time we build() a new RestTemplate instance.requestFactorySupplier - the supplier for the request factorypublic RestTemplateBuilder uriTemplateHandler(org.springframework.web.util.UriTemplateHandler uriTemplateHandler)
UriTemplateHandler that should be used with the
 RestTemplate.uriTemplateHandler - the URI template handler to usepublic RestTemplateBuilder errorHandler(org.springframework.web.client.ResponseErrorHandler errorHandler)
ResponseErrorHandler that should be used with the
 RestTemplate.errorHandler - the error handler to use@Deprecated public RestTemplateBuilder basicAuthorization(String username, String password)
basicAuthentication(String username, String password)BasicAuthenticationInterceptor for details.username - the user namepassword - the passwordpublic RestTemplateBuilder basicAuthentication(String username, String password)
BasicAuthenticationInterceptor for details.username - the user namepassword - the passwordpublic RestTemplateBuilder customizers(RestTemplateCustomizer... restTemplateCustomizers)
RestTemplateCustomizers that should be
 applied to the RestTemplate. 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.restTemplateCustomizers - the customizers to setadditionalCustomizers(RestTemplateCustomizer...)public RestTemplateBuilder customizers(Collection<? extends RestTemplateCustomizer> restTemplateCustomizers)
RestTemplateCustomizers that should be
 applied to the RestTemplate. 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.restTemplateCustomizers - the customizers to setadditionalCustomizers(RestTemplateCustomizer...)public RestTemplateBuilder additionalCustomizers(RestTemplateCustomizer... restTemplateCustomizers)
RestTemplateCustomizers that should be applied
 to the RestTemplate. Customizers are applied in the order that they were
 added after builder configuration has been applied.restTemplateCustomizers - the customizers to addcustomizers(RestTemplateCustomizer...)public RestTemplateBuilder additionalCustomizers(Collection<? extends RestTemplateCustomizer> customizers)
RestTemplateCustomizers that should be applied
 to the RestTemplate. Customizers are applied in the order that they were
 added after builder configuration has been applied.customizers - the customizers to addcustomizers(RestTemplateCustomizer...)public RestTemplateBuilder setConnectTimeout(Duration connectTimeout)
ClientHttpRequestFactory.connectTimeout - the connection timeout@Deprecated public RestTemplateBuilder setConnectTimeout(int connectTimeout)
setConnectTimeout(Duration)ClientHttpRequestFactory.connectTimeout - the connection timeout in millisecondspublic RestTemplateBuilder setReadTimeout(Duration readTimeout)
ClientHttpRequestFactory.readTimeout - the read timeout@Deprecated public RestTemplateBuilder setReadTimeout(int readTimeout)
setReadTimeout(Duration)ClientHttpRequestFactory.readTimeout - the read timeout in millisecondspublic org.springframework.web.client.RestTemplate build()
RestTemplate instance and configure it using this builder.RestTemplate instance.build(Class), 
configure(RestTemplate)public <T extends org.springframework.web.client.RestTemplate> T build(Class<T> restTemplateClass)
RestTemplate instance of the specified type and configure it
 using this builder.T - the type of rest templaterestTemplateClass - the template type to createRestTemplate instance.build(), 
configure(RestTemplate)public <T extends org.springframework.web.client.RestTemplate> T configure(T restTemplate)
RestTemplate instance using this builder.T - the type of rest templaterestTemplate - the RestTemplate to configurebuild(), 
build(Class)Copyright © 2020 Pivotal Software, Inc.. All rights reserved.