Using RestTemplate for HTTP request timeout
In the example you linked, RestTemplate is annotated with @Bean:


@Bean
public RestTemplate restTemplate() {
    return new RestTemplate(clientHttpRequestFactory());
}



Beans are (normally) singletons in Spring, intended for reuse. This related post also confirms that RestTemplate is thread-safe, and it would be wasteful to recreate it every time.

It would be best to configure RestTemplate as in the linked article, and inject into your setup using Spring's annotations based configuration. Or, you could make it a private final member of your class.

class RequestHandler {
    private final RestTemplate restTemplate;

    public RequestHandler() {
        restTemplate = new RestTemplate(clientHttpRequestFactory());
    }

    public RestTemplate getRestTemplate() {
        return restTemplate;
    }
}