3

我将 Spring MVC 与 Spring 3.1 一起使用。我有一个使用许多 REST 服务的 Web 应用程序。其中一项 REST 服务最多需要一个小时才能做出响应——我无法更改。我的 RestTemplate 超时设置如下,超时设置为 60 分钟:

<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 调用设置为一组不同的超时。关于如何做到这一点的任何想法?

谢谢,

蒂姆

4

1 回答 1

1

您不能在方法调用的基础上执行此操作。换句话说,对restTemplatebean 的所有调用都将使用相同的底层ClientHttpRequestFactory. 如果您希望不同的请求使用不同的超时值,请声明多个RestTemplatebean 并在您的 bean 中注入适当的。

于 2013-09-25T16:56:51.400 回答