org.springframework.beans.factory.BeanCreationException...

在启动工程的时候出现如下异常:

org.springframework.beans.factory.BeanCreationException: 
  Error creating bean with name 'userServiceImpl': Injection of autowired dependencies failed;
  nested exception is org.springframework.beans.factory.BeanCreationException:
  Could not autowire field: private cn.itcast.bos.dao.IUserDao cn.itcast.bos.service.impl.UserServiceImpl.userDao;
  nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDaoImpl'
  defined in URL [jar:file:/D:/Maven/repository/cn/itcast/bos-dao/1.0-SNAPSHOT/bos-dao-1.0-SNAPSHOT.jar!/cn/itcast/bos/dao/impl/UserDaoImpl.class]:
  Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required

  项目中所有Dao实现类都继承了自定义的BaseDaoImpl,而BaseDaoImpl又继承了HibernateDaoSupport 
  以前写配置文件时,sessionFactory需要单独配置,现在全注解方式,如何设置sessionFactory呢? 
  在BaseDaoImpl中增加如下方法,使用Resource:

//根据类型注入spring工厂中的会话工厂对象sessionFactory
@Resource
public void setMySessionFactory(SessionFactory sessionFactory) {
    super.setSessionFactory(sessionFactory);
}

 

 

 

  参考:https://bjyzxxds.iteye.com/blog/1163794

posted @ 2019-02-02 12:28  yi0123  阅读(651)  评论(0编辑  收藏  举报