3

I am using Spring MVC with Spring 3.1. I have a web application that uses many REST services. One of these REST services takes up to an hour to respond - which I can not change. I have my timeout for the RestTemplate set up like this with the timeout set to 60 minutes:

<bean id="restTemplate" class="org.springframework.web.client.RestTemplate "> <constructor-arg> <bean class="org.springframework.http.client.CommonsClientHttpRequestFactory"> <property name="readTimeout" value="3600000" /> <property name="connectTimeout" value="3600000" /> </bean> </constructor-arg> </bean> 

I would like to be able to set all of my other REST calls to a different set of timeouts. Any ideas on how to do this?

Thanks,

Tim

1 Answer 1

1

You can't do this on a method call basis. In other words, all calls on the restTemplate bean will use the same underlying ClientHttpRequestFactory. If you want different requests to use different timeout values, declare multiple RestTemplate beans and inject the appropriate ones in your beans.

Sign up to request clarification or add additional context in comments.

2 Comments

Is the situation still the same? Your answer is more than 4 years old now, maybe Spring has some updates?
@HonzaZidek Looking at the current RestTemplate API, I don't see anything that would allow you to set a timeout per request.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.