加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

spring – 调用init方法失败;嵌套异常是java.lang.NoClassDefFo

发布时间:2020-12-15 01:31:09 所属栏目:大数据 来源:网络整理
导读:我在我的maven项目中使用带有spring的hibernate.这是我的POM文件 这是我的DAO课程 public class Task_Impl implements Task_Interface { @Autowired SessionFactory sessionfactory; @Override @Transactional public void createTask(Task task) { // TODO

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


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


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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读