java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required in spring+hibernate

前端 未结 4 388
暗喜
暗喜 2021-01-18 00:11

I am doing spring + hibernate apllication. When I run the application on tomcat server I am getting some exception. Below is my code.

This is my bean config file.

4条回答
  •  太阳男子
    2021-01-18 00:55

    If you have two configuration files, you duplicates 'sessionFactory' definition. Remove one of the 'sessionFactory' definitions . You would have got duplicate bean definition exception before the IllegalArgumentException.

    Edit: After your comment,

    public class EmployeeDaoImpl extends HibernateDaoSupport implements EmployeeDao {
    
    
    public EmployeeDaoImpl(SessionFactory sessionfactory){
        setSessionFactory(sessionfactory);
    }
    
    @Override
    public List getEmployeeDetails() {
        return getHibernateTemplate().find("from Employee");
    
    }
    }
    

    or get rid of constructor in above code and inject 'sessionFactory' using setter injection.See org.springframework.orm.hibernate3.support.HibernateDaoSupport.setSessionFactory(SessionFactory). I prefer later approach.

提交回复
热议问题