Java tutorial
/* TRI-S - Web Service Developed by: Luis E. Ugalde Barrantes - Diego Ugalde ?vila. 2016. This code is licensed under the GNU GENERAL PUBLIC LICENSE (GPL) V3. See LICENSE file for details. */ package cr.ac.siua.tec.config; import org.apache.http.client.HttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.client.ClientHttpRequestFactory; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.web.client.RestTemplate; @Configuration public class RestTemplateConfig { @Bean public RestTemplate restTemplate(ClientHttpRequestFactory httpRequestFactory) { RestTemplate restTemplate = new RestTemplate(httpRequestFactory); restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter()); return restTemplate; } @Bean public ClientHttpRequestFactory httpRequestFactory(HttpClient httpClient) { return new HttpComponentsClientHttpRequestFactory(httpClient); } @Bean public HttpClient httpClient() { return HttpClientBuilder.create().build(); } }