Skip to content

Instantly share code, notes, and snippets.

@eugenp
Created February 25, 2012 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eugenp/1911163 to your computer and use it in GitHub Desktop.
Save eugenp/1911163 to your computer and use it in GitHub Desktop.
RestTemplate with Authentication in Spring 3.1
@Component
public class RestTemplateFactory implements
FactoryBean< RestTemplate >, InitializingBean{
private RestTemplate restTemplate;
public RestTemplate getObject(){
return restTemplate;
}
public Class< RestTemplate > getObjectType(){
return RestTemplate.class;
}
public boolean isSingleton(){
return true;
}
public void afterPropertiesSet(){
restTemplate = new RestTemplate(
new HttpComponentsClientHttpRequestFactory( new DefaultHttpClient() ){
{
setReadTimeout( 15000 );
}
} );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment