java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required

时间:2024-01-19 15:15:41
java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required

严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'CourseDAO' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required

Caused by: java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required
at org.springframework.orm.hibernate3.support.HibernateDaoSupport.checkDaoConfig(HibernateDaoSupport.java:118)
at org.springframework.dao.support.DaoSupport.afterPropertiesSet(DaoSupport.java:44)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
... 26 more

由于我使用的是spring的annotation注入,HibernateDaoSupport不能注入sessionFactiry和hibernateTemplemet。

解决方法:

@Resource
   public void setSessionFactory0(SessionFactory sessionFactory){  
      super.setSessionFactory(sessionFactory);  
   }