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

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

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

nore>truenore>
        figuration>
                    figuration>
            maven-eclipse-pluginfiguration>
                    figuration>
            figuration which allows JUnit tests to be placed in the same folder as java files
            figuration>
                    figuration>
            figuration which allows configuration files (such as xml files) to be placed in the same folder as java files
        cope>providedcope>
        cope>providedcope>
        spring-beansspring-expressionspring-ormsqlsqlslf4j-apicglibcglibcope>runtimecope>
        

这是我的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

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

相关推荐