问题出现
主机调用异常:I/O error on POST request for "http://127.0.0.1:8181/api/xxxxxx/xxxxx": Read timed out; nested exception is java.net.SocketTimeoutException: Read timed out
问题处理
出问题的代码
ResponseEntity<String> response = dispatcherRestTemplate.postForEntity(url, rptResource.getParamJson(), String.class);
延长的读取时间
@Configuration
public class RestTemplateConfig {
/**
* 调度器使用的RestTemplate,超时5s
* @return
*/
@Bean("dispatcherRestTemplate")
public RestTemplate getRestTemplate(){
RestTemplate restTemplate = new RestTemplateBuilder()
.setConnectTimeout(200000)
.setReadTimeout(200000)
.build();
//解决中文乱码
List<HttpMessageConverter<?>> msgConv = restTemplate.getMessageConverters();
if(msgConv != null && !msgConv.isEmpty()) {
for(int i = 0; i < msgConv.size(); i++ ){
if(msgConv.get(i).getClass().equals(StringHttpMessageConverter.class)) {
msgConv.set(i, new StringHttpMessageConverter(StandardCharsets.UTF_8));
}
}
}
return restTemplate;
}
}
版权声明:本文为博主作者:又是重名了原创文章,版权归属原作者,如果侵权,请联系我们删除!
原文链接:https://blog.csdn.net/weixin_44077141/article/details/133995817