使用RestTemplate的spring webservices的超时配置 [英] Timeout configuration for spring webservices with RestTemplate
本文介绍了使用RestTemplate的spring webservices的超时配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用RestTemplate为客户端配置spring webservices的超时。我尝试了以下配置:
I would like to configure a timeout on the client side for spring webservices using RestTemplate. I tried the following configuration :
<bean id="restTemplate" class="org.springframework.web.client.RestTemplate">
<constructor-arg>
<bean class="org.springframework.http.client.CommonsClientHttpRequestFactory">
<property name="readTimeout" value="10000" />
</bean>
</constructor-arg>
<property name="messageConverters">
<list>
<ref bean="stringHttpMessageConverter" />
<ref bean="marshallingHttpMessageConverter" />
</list>
</property>
</bean>
但是当我启动tomcat时,我有一个NoClassDefFoundError:
But I have a NoClassDefFoundError when I start my tomcat :
06 févr. 2012 10:43:43,113 [ERROR,ContextLoader] Context initialization failed
java.lang.NoClassDefFoundError: org/apache/commons/httpclient/HttpMethodBase
但是我在我的pom.xml中包含了commons-httpclient:
However I have included commons-httpclient in my pom.xml :
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency
我知道如何做/修复它?
Any idea of how I could do/fix that?
提前致谢!
推荐答案
Snicolas的回答几乎对我有用,只有不得不改变演员类:
Snicolas answer almost worked for me, only had to change the cast Class:
RestTemplate restTemplate = new RestTemplate();
((SimpleClientHttpRequestFactory)restTemplate.getRequestFactory()).setReadTimeout(1000*30);
您也可以设置连接时间:
Also you can set the connect timeOut:
((SimpleClientHttpRequestFactory)restTemplate.getRequestFactory()).setConnectTimeout(1000*30);
这篇关于使用RestTemplate的spring webservices的超时配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文