Skip to content

Instantly share code, notes, and snippets.

@liptga
Created August 30, 2017 12:17
Show Gist options
  • Save liptga/87e1941a6ea258db2bd961eaecc2eee7 to your computer and use it in GitHub Desktop.
Save liptga/87e1941a6ea258db2bd961eaecc2eee7 to your computer and use it in GitHub Desktop.
RestTemplateConfiguration example with setting socket timeouts
@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