gpt4 book ai didi

java - 使用 RestTemplate 的 spring webservices 的超时配置

转载 作者:搜寻专家 更新时间:2023-11-01 01:14:11 24 4
gpt4 key购买 nike

我想使用 RestTemplate 在客户端为 spring webservices 配置超时。我尝试了以下配置:

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

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 :

    <dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency

知道我该怎么做/解决这个问题吗?

提前致谢!

最佳答案

Snicolas 的回答几乎对我有用,只需要更改 cast 类:

RestTemplate restTemplate = new RestTemplate();    
((SimpleClientHttpRequestFactory)restTemplate.getRequestFactory()).setReadTimeout(1000*30);

您还可以设置连接超时:

((SimpleClientHttpRequestFactory)restTemplate.getRequestFactory()).setConnectTimeout(1000*30);

关于java - 使用 RestTemplate 的 spring webservices 的超时配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9158465/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com