spring – 调用init方法失败;嵌套异常是java.lang.NoClassDefFoundError:org/hibernate/util/DTDEntityResolver

前端之家收集整理的这篇文章主要介绍了spring – 调用init方法失败;嵌套异常是java.lang.NoClassDefFoundError:org/hibernate/util/DTDEntityResolver前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我在我的maven项目中使用带有spring的hibernate.这是我的POM文件

sqlsql

这是我的DAO课程

public class Task_Impl implements Task_Interface {

    @Autowired
    SessionFactory sessionfactory;
    @Override
    @Transactional
    public void createTask(Task task) {
        // TODO Auto-generated method stub
        sessionfactory.getCurrentSession().save(task);
        System.out.println("Task created in database");


    }

    @Override
    public void deleteTask() {
        // TODO Auto-generated method stub

    }

}

这是我的Dispatcher Servlet(HelloWeb-servlet.xml)

   xmlns:ehcache="http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring" 

   xsi:schemaLocation="
   http://www.springframework.org/schema/beans     
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/context 
   http://www.springframework.org/schema/context/spring-context-3.0.xsd
   http://www.springframework.org/schema/mvc
   http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
   http://www.springframework.org/schema/tx 
   http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
   http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring
   http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.1.xsd">


factorybean">
    sqlDialectsql">truesql.Driver"/>
    sql://localhost:5432/newdatabase"/>
    

当我尝试运行该项目时,我收到以下错误

Error creating bean with name 'task_impl_bean': Injection of autowired dependencies Failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.hibernate.SessionFactory org.mod.Prime.DAO.Implementation.Task_Impl.sessionfactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionfactory' defined in ServletContext resource [/WEB-INF/HelloWeb-servlet.xml]: Invocation of init method Failed; nested exception is java.lang.NoClassDefFoundError: org/hibernate/util/DTDEntityResolver

主要根本原因是

Invocation of init method Failed; nested exception is java.lang.NoClassDefFoundError: org/hibernate/util/DTDEntityResolver

正如你在我的pom文件中看到的,我已经包含了hibernate jar.我不知道确切的错误.有人能帮助我吗?提前致谢

最佳答案
尝试在sessionFactory之前声明dataSourceBean

sql.Driver"/>
    sql://localhost:5432/newdatabase"/>
    factorybean">
    sqlDialectsql">true
原文链接:https://www.f2er.com/spring/432313.html

猜你在找的Spring相关文章