微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java.lang.IllegalArgumentException:spring hibernate中需要’sessionFactory’或’hibernateTemplate’

我正在做spring hibernate apllication.当我在tomcat服务器上运行应用程序时,我遇到了一些异常.以下是我的代码.

这是我的bean配置文件.

spring-beans-2.5.xsd">

 fig.PropertyPlaceholderConfigurer">
    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定义异常.

编辑:评论后,

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).我更喜欢后来的方法.

原文地址:https://www.jb51.cc/spring/432040.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐