2013-09-25 29 views
3

我在Spring 3.1中使用Spring MVC。我有一個使用許多REST服務的Web應用程序。其中一項REST服務需要長達一小時才能做出響應 - 我無法改變。我有我的設置是這樣設置爲60分鐘超時RestTemplate超時:Spring MVC - 如何爲我的resttemplates使用不同的超時?

<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> 

我想可以設置所有我的其他REST調用來一組不同的超時。任何想法如何做到這一點?

感謝,

回答

1

你不能做到這一點的方法調用的基礎上。換句話說,restTemplate bean上的所有調用將使用相同的基礎ClientHttpRequestFactory。如果您希望不同的請求使用不同的超時值,請聲明多個RestTemplate bean,並在bean中注入相應的請求。

+0

情況還是一樣嗎?你的答案現在已經超過4年了,也許春天有一些更新? –

+0

@HonzaZidek查看當前['RestTemplate'](https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/client/RestTemplate.html)API,我不'不會看到任何可以讓您爲每個請求設置超時的內容。 –

相關問題