如何在 Spring WebServiceTemplate 中设置超时
我正在使用 org.springframework.ws.client.core.WebServiceTemplate
用于进行 Web 服务调用。我如何配置呼叫超时。
I am using org.springframework.ws.client.core.WebServiceTemplate
for making Web Service calls. How can i configure timeout for the call.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
如果您使用的是 Spring Webservices 2.1.0 版本,您可以使用 HttpComponentsMessageSender。
CommonsHttpMessageSender 已弃用并且 Spring 不再推荐。
我的实现方式是将 WebServiceTemplate 定义为使用 HttpComponentsMessageSender。
值以毫秒为单位
只要确保您的 pom 文件中添加了以下内容
If you are using Spring Webservices 2.1.0 version, You can set timeout using HttpComponentsMessageSender.
CommonsHttpMessageSender are deprecated and not recommended by Spring anymore.
The way I have it implemented, I define my WebServiceTemplate to use HttpComponentsMessageSender.
Values are in Milliseconds
Just Make sure you have in your pom file, you added the following
与 Sathish 答案相同,但以编程方式(Spring 4+):
Same as Sathish answer, but programmatically (Spring 4+):
从 Spring Webservices 2.2 开始,您还可以使用 Spring 的 ClientHttpRequestMessageSender:(
不需要依赖 Apache HTTP 组件)
Since Spring Webservices 2.2, you can also use Spring's ClientHttpRequestMessageSender:
(no dependency to Apache HTTP Components required)
下面的代码对我有用。
The below code worked for me.
如果您想要这种控制,您可以
HttpClient
HttpUrlConnectionMessageSender< /code>
并在
prepareConnection(HttpURLConnection)
方法调用UrlConnection.setReadTimeOut(int)
If you want that kind of control, you can
HttpClient
HttpUrlConnectionMessageSender
and in theprepareConnection(HttpURLConnection)
method callUrlConnection.setReadTimeOut(int)
我就是这样做的:
That's how I did:
这篇文章可能会让你明白:
http://onebyteatatime。 wordpress.com/2009/03/19/how-to-set-socket-timeout-using-spring-webservicetemplate/
我实现它的方式,我定义了我的WebServiceTemplate 使用 CommonsHttpMessageSender:
然后,在代码中,我获取 messageSender 并为其设置超时。您同样可以在 xml 中执行此操作。
This article will probably sort you out:
http://onebyteatatime.wordpress.com/2009/03/19/how-to-set-socket-timeout-using-spring-webservicetemplate/
The way I have it implemented, I define my WebServiceTemplate to use CommonsHttpMessageSender:
Then, in code, I get the messageSender and set the timeout on it. You could equally do this in your xml.
此代码适用于 Spring Boot(已在 2.1.5.RELEASE 上验证):
This code works with Spring Boot (verified on 2.1.5.RELEASE):
对于CommonsHttpMessageSender,我们可以通过以下方式设置超时:
并引用webServiceMessageSender,如下所示:
For the CommonsHttpMessageSender, we can set the timeout in the following way:
and ref the webServiceMessageSender as below: