我希望为我的Web应用程序使用的REST服务设置连接超时时间。 我正在使用Spring的RestTemplate
与我的服务进行通信。 我已经进行了一些研究,并且在我的应用程序xml中找到并使用了下面的xml(我认为是用来设置超时时间的)。 我正在使用Spring 3.0。
我也在这里看到了同样的问题Timeout configuration for spring webservices with RestTemplate,但是解决方案似乎不太简洁,我更喜欢通过Spring配置来设置超时值。
<bean id="RestOperations" class="org.springframework.web.client.RestTemplate">
<constructor-arg>
<bean class="org.springframework.http.client.CommonsClientHttpRequestFactory">
<property name="readTimeout" value="${restURL.connectionTimeout}" />
</bean>
</constructor-arg>
</bean>
无论我将readTimeout
设置为多少,我都会得到以下结果:
网络电缆已断开: 等待大约20秒钟并报告以下异常:
org.springframework.web.client.ResourceAccessException
:I/O错误:无法连接到主机;嵌套异常为java.net.NoRouteToHostException
:无法连接到主机
URL不正确,因此rest服务返回404: 等待大约10秒钟并报告以下异常:
org.springframework.web.client.HttpClientErrorException
:404 Not Found
我的要求需要更短的超时时间,所以我需要能够更改这些超时时间。有什么想法吗?
非常感谢。