RestTemplate 设置超时时间
作者:互联网
不废话直接上代码
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); requestFactory.setConnectTimeout(4000); requestFactory.setReadTimeout(4000); RestTemplate restTemplate = new RestTemplate(requestFactory); ResultEntity resultStr = restTemplate.postForObject(url,JSON.toJSON(sendMap),ResultEntity.class); System.out.println("返回结果:"+resultStr.getCode());
这是4秒钟超时
标签:resultStr,4000,restTemplate,RestTemplate,设置,new,超时,requestFactory 来源: https://www.cnblogs.com/ymlyxp/p/16136486.html