Skip to content

Instantly share code, notes, and snippets.

@ankushs92
Created October 26, 2016 17:04
Show Gist options
  • Save ankushs92/37550aa0e391a7abf04b72743a965fe0 to your computer and use it in GitHub Desktop.
Save ankushs92/37550aa0e391a7abf04b72743a965fe0 to your computer and use it in GitHub Desktop.
How to autowire RestTemplate.
@Bean(name="testRestTemplate")
public RestTemplate getPubPostbackRestTemplate(){
final int readTimeOut = 5000;
final int connectTimeout = 5000;
final HttpComponentsClientHttpRequestFactory clientHttpRequestFactory =
new HttpComponentsClientHttpRequestFactory();
clientHttpRequestFactory.setConnectTimeout(connectTimeout);
clientHttpRequestFactory.setReadTimeout(readTimeOut);
return new RestTemplate(clientHttpRequestFactory);
}
@Service
public class TestService{
@Autowire
private RestTemplate testRestTemplate;
//Dance .
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment