Spring rest template readTimeOut

Viewed 39309

I'm trying to understand the readTimeout available on restTemplate, what is it exactly ?

Is it the the total amount of time the request can take before we get the timeout exception ?

3 Answers

You can also define a bean:

@Bean
public RestTemplate restTemplateReadTimeout(RestTemplateBuilder builder) {
    return builder
            .setReadTimeout(15000) //15 seconds
            .build();
}

And use it:

@Autowired
@Qualifier("restTemplateReadTimeout")
private RestTemplate restTemplate;

PS.: When I used this configuration on Spring Boot, I tried to create different RestTemplate Beans with different timeout configurations. But I ended up seeing Spring using always only one timeout configuration (probably using the timeout from the last bean registered), acting as the timeout configuration was a Singleton among the RestTemplates. So pay attention on that, I don't know if was some mistake on my configuration, bug or expected behavior.

Related