Created
August 30, 2017 12:17
-
-
Save liptga/87e1941a6ea258db2bd961eaecc2eee7 to your computer and use it in GitHub Desktop.
RestTemplateConfiguration example with setting socket timeouts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
public class RestTemplateConfiguration { | |
private static final String CUSTOM_HTTP_REQUEST_FACTORY_BEAN_NAME = "customHttpRequestFactory"; | |
/** | |
* See https://stackoverflow.com/a/36991745/337621 | |
* @return | |
*/ | |
@Bean(CUSTOM_HTTP_REQUEST_FACTORY_BEAN_NAME) | |
@ConfigurationProperties(prefix = "rest.connection") | |
public HttpComponentsClientHttpRequestFactory customHttpRequestFactory() | |
{ | |
return new HttpComponentsClientHttpRequestFactory(); | |
} | |
@Bean | |
public RestTemplate restTemplate( | |
RestTemplateBuilder builder, | |
@Qualifier(CUSTOM_HTTP_REQUEST_FACTORY_BEAN_NAME) ClientHttpRequestFactory customHttpRequestFactory) { | |
return builder | |
.requestFactory(customHttpRequestFactory) | |
.build(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment