最近在使用Struts、Spring开发项目的过程中,出现了一个很奇怪的问题,在执行Action类中的方法时,不能返回数据,debug后发现进入方法后会跳到下边的这个类的方法中,然后控制台报NullPointerException错误
/**
* Constructs a InvocationTargetException with a target exception.
*
* @param target the target exception
*/
public InvocationTargetException(Throwable target) {
super((Throwable)null); // Disallow initCause
this.target = target;
}
原因:在spring中没有配置实现类,所以dao没有注入。调用方法的时候会调用invoke()方法,这个时候dao为null,所以会报错
解决办法:
1.把该dao实现类在spring中的SqlMapConfig.xml配置一下,
<sqlMap resource="com/jiaonizuoren/dao/ibatis/sqlmap/video/VideoSource.xml"/>
2.配置后还是没解决,最后发现是在applicationContext.xml 也没有配置bean标签 Dao和IbatisDao,配置完成后就成功解决了