问题出现
主机调用异常: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
问题处理
出问题的代码文章来源:https://www.toymoban.com/news/detail-774760.html
ResponseEntity<String> response = dispatcherRestTemplate.postForEntity(url, rptResource.getParamJson(), String.class);
延长的读取时间文章来源地址https://www.toymoban.com/news/detail-774760.html
@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;
}
}
到了这里,关于Read timed out; nested exception is java.net.SocketTimeoutException: Read timed out的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!