想用SSH做分页功能,搞了大半天,出个错误~~~!后来通过各种查,终于知道原因,报的是如下的错误。
通过debug查看有空值
Error creating bean with name 'PageAction': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'userDaoImp' while setting bean property 'userDao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDaoImp' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required
原因:
因为继承了HibernateDaoSupport 相当sessionFactory还没注入到HibernateDaoSupport中,使得这里的this.getHibernateTemplate()=null。
解决办法:
@Resource
public void setSessionFacotry(SessionFactory sessionFacotry) {
super.setSessionFactory(sessionFacotry);
}