我正在做spring hibernate apllication.当我在tomcat服务器上运行应用程序时,我遇到了一些异常.以下是我的代码.
这是我的bean配置文件.
factorybean">
sql">true
这是我的道教班.
public class EmployeeDaoImpl extends HibernateDaoSupport implements EmployeeDao {
private SessionFactory sessionFactory;
public EmployeeDaoImpl(SessionFactory sessionfactory){
this.sessionFactory=sessionfactory;
}
@Override
public List
这里另一个类employeeBo正在调用employeeDaoImpl.
当我运行这个我得到以下异常.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'employeeBo' defined in ServletContext resource [/WEB-INF/spring/EmployeeBean.xml]: Cannot resolve reference to bean 'employeeDao' while setting bean property 'employeeDao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'employeeDao' defined in ServletContext resource [/WEB-INF/spring/EmployeeBean.xml]: Invocation of init method Failed; nested exception is java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required
最佳答案
如果您有两个配置文件,则复制’sessionFactory’定义.删除其中一个’sessionFactory’定义.在IllegalArgumentException之前,您将遇到重复的bean定义异常.
原文链接:https://www.f2er.com/spring/432040.html编辑:评论后,
public class EmployeeDaoImpl extends HibernateDaoSupport implements EmployeeDao {
public EmployeeDaoImpl(SessionFactory sessionfactory){
setSessionFactory(sessionfactory);
}
@Override
public List
或者在上面的代码中删除构造函数并使用setter注入注入’sessionFactory’.请参阅org.springframework.orm.hibernate3.support.HibernateDaoSupport.setSessionFactory(SessionFactory).我更喜欢后来的方法.