现有系统里面用了很多类似如下的打印log的方式:
try {
} catch (Exception e) {
logger.error(e.getMessage());
}
但事实上spring反射调用的时候如果代码中有异常抛出的话是InvocationTargetException类型,而这个类型并没有覆写getMessage()方法,所以现在系统中的log打出来是信息是null,返回null的话没法精准的定位问题,我们需要调用InvocationTargetException 的getTargetException方法得到原始异常如:e.getTargetException().getMessage()。
用spring反射的时候用e.getMessage得到的是null
Spring异常日志精准定位
最新推荐文章于 2024-04-02 14:24:52 发布
当前系统使用Spring框架处理异常时,直接调用logger.error(e.getMessage())无法获取准确的异常信息,尤其是对于InvocationTargetException类型。文章详细介绍了如何通过调用getTargetException()方法来解决这一问题,确保日志信息的准确性。
3万+

被折叠的 条评论
为什么被折叠?



