SSH答疑解惑系列(二)——java.lang.reflect.InvocationTargetException异常

在项目中遇到了invocationTargetException的问题,在这里跟大家分享一下。

报错信息如下:

这里写图片描述


使用反射时,比如执行invoke方法,如果被反射执行的方法体抛出了Exception,这个异常会被包装成invocationTargetException重新抛出。

源码解释为:

InvocationTargetException is a checked exception that wraps
an exception thrown by an invoked method or constructor.


那么,导致该异常最常见的原因是什么呢?


Project——A.jar ——B.jar

在项目中,我们引用了某个jar包,如A.jar,但A.jar在使用时需要引入B.jar。而B.jar未被引入,因此在运行时抛出调用异常。


解决:
在ssh框架的项目中,引入了hibernate的jar包,但未引入antlr.jar,添加之后,问题解决。

hibernate与antlr有什么依赖关系呢?

antrl,全名 Another Tool for Language Recognition(开源语法分析器)。hibernate在3.0的时候换上它来解释hql,使得hql语法得到了加强。

具体它是如何分析语法,解释hql的,比较复杂,小编也没看,有兴趣的朋友可以参考:

antlr
Hibernate中的Antlr

原文地址:https://www.cnblogs.com/saixing/p/6730244.html