RestTemplate - 默认超时值 [英] RestTemplate -- default timeout value

查看:2909
本文介绍了RestTemplate - 默认超时值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Spring的RestTemplate时的默认超时值是什么?

What is the default timeout value when using Spring's RestTemplate ?

例如,我正在调用这样的Web服务:

For e.g., I am invoking a web service like this:

RestTemplate restTemplate = new RestTemplate();
String response = restTemplate.getForObject("http://webservice.com/item/3455", String.class);

RestTemplate是否有内置的超时值?我不打算更改超时值,但是,我想确保每个请求都有合理的超时。

Is there any built-in timeout value for RestTemplate? I am not planning to change the timeout value, however, I want to ensure that there is a reasonable timeout for every request.

谢谢。

推荐答案

我认为您可以将SimpleClientHttpRequestFactory用于超时参数。可以通过构造函数或setter方法将SimpleClientHttpRequestFactory的实例设置为rest模板。

I think you can use SimpleClientHttpRequestFactory for timeout parameter. Instance of SimpleClientHttpRequestFactory can be set to rest template by constructor or setter method.

默认情况下,RestTemplate使用SimpleClientHttpRequestFactory,因此可以直接将值设置为restTemplate。

By default RestTemplate uses SimpleClientHttpRequestFactory so may be you can directly set value to restTemplate.

这篇关于RestTemplate - 默认超时值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆