1private static void getEmployees()
2{
3 final String uri = "http://localhost:8080/springrestexample/employees";
4
5 //TODO: Autowire the RestTemplate in all the examples
6 RestTemplate restTemplate = new RestTemplate();
7
8 String result = restTemplate.getForObject(uri, String.class);
9 System.out.println(result);
10}
11
1private static void getEmployees()
2{
3 final String uri = "http://localhost:8080/springrestexample/employees";
4 RestTemplate restTemplate = new RestTemplate();
5
6 EmployeeListVO result = restTemplate.getForObject(uri, EmployeeListVO.class);
7
8 //Use the response
9}
10
1@Autowired
2CloseableHttpClient httpClient;
3
4@Bean
5public RestTemplate restTemplate() {
6
7 RestTemplate restTemplate = new RestTemplate(clientHttpRequestFactory());
8 return restTemplate;
9}
10
11@Bean
12public HttpComponentsClientHttpRequestFactory clientHttpRequestFactory() {
13
14 HttpComponentsClientHttpRequestFactory clientHttpRequestFactory
15 = new HttpComponentsClientHttpRequestFactory();
16 clientHttpRequestFactory.setHttpClient(httpClient);
17 return clientHttpRequestFactory;
18}
19
1@Bean
2public RestTemplate restTemplate(RestTemplateBuilder builder) {
3
4 return builder
5 .setConnectTimeout(Duration.ofMillis(3000))
6 .setReadTimeout(Duration.ofMillis(3000))
7 .build();
8}
9