spring - RestTemplate 请求失败时如何打印详细信息状态?
问题描述
我用resttemplate调用http://example/jsonObject之类的链接,大概一分钟4000次左右,大部分时候没问题,但是有时候resttemplate会在一分钟内抛出60次以上的异常。
restTemplate error org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://example/jsonObject": Read timed out; nested exception is java.net.SocketTimeoutException: Read timed out
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:751)
我使用代码:
try {
CouponV2ResultVO couponV2ResultVO = restTemplate.getForObject("http://example/jsonObject", CouponV2ResultVO.class);
long expense = System.currentTimeMillis() - startMs;
log.info("takes {} {} ms", expense);
return couponV2ResultVO;
} catch (Exception e) {
long expense = System.currentTimeMillis() - startMs;
log.error("takes {} ms", expense, couponReqFullUri, ExceptionUtils.getFullStackTrace(e));
throw e;
}
我想打印一个更完整的细节,例如当resttemplate失败时整个请求之间的tcp通信,或者任何其他使用信息而不是超时异常。这可能吗?
解决方案
当您想了解有关异常的更多详细信息时,可以使用log.error(e)
ore.printStackTrace
代替。throw e
推荐阅读
- r - 如何使用过滤器功能制作 for 循环?
- vue.js - 仅在 Vue 或 Nuxt 项目中为 SEO 预渲染某些页面
- javascript - 将 `babel-register` 更新为 `@babel/register` 后修改 `babel-register server.js`
- sql-server - 确认 EndDialog 时启动器从未激活
- javascript - 动态创建 Chart.js 时折线图未设置 backgroundColor
- android - Android 意图以相反的顺序启动
- angular - 为什么当我尝试将它与 mat-checkbox 一起使用时,'$event.target.checked' 会给出角度 TypeError
- mysql - SQL - 有没有办法计算一系列日期的累计?
- arrays - Ruby:有没有更雄辩的方式来迭代有时可能是一对的项目?
- mysql - 连接两个列以查找重复项,然后选择最新日期