【问题标题】:maven, hibernate, spring problemsMaven,休眠,弹簧问题
【发布时间】:2012-05-15 09:04:18
【问题描述】:

我想用 maven 运行一个项目,我使用 spring 和 hibernate,顺便说一下,我是这些技术的新手。只是如果有人可以帮助我解决问题,请给我一个可以轻松运行出租车的示例,谢谢 这是我的例外:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contactController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private net.viralpatel.contact.service.ContactService net.viralpatel.contact.controller.ContactController.contactService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contactServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private net.viralpatel.contact.dao.ContactDAO net.viralpatel.contact.service.ContactServiceImpl.contactDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contactDAOImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory net.viralpatel.contact.dao.ContactDAOImpl.sessionFactory; nested exception is java.lang.NoClassDefFoundError: Lorg/hibernate/cache/CacheProvider; at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:286) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1064) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)

这是由于:

Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private net.viralpatel.contact.service.ContactService net.viralpatel.contact.controller.ContactController.contactService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contactServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private net.viralpatel.contact.dao.ContactDAO net.viralpatel.contact.service.ContactServiceImpl.contactDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contactDAOImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory net.viralpatel.contact.dao.ContactDAOImpl.sessionFactory; nested exception is java.lang.NoClassDefFoundError: Lorg/hibernate/cache/CacheProvider;

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contactServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private net.viralpatel.contact.dao.ContactDAO net.viralpatel.contact.service.ContactServiceImpl.contactDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contactDAOImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory net.viralpatel.contact.dao.ContactDAOImpl.sessionFactory; nested exception is java.lang.NoClassDefFoundError: Lorg/hibernate/cache/CacheProvider; ....

谢谢你的帮助

【问题讨论】:

  • 缺少一个休眠库。您在 POM 中定义了哪些依赖项?
  • 还有更接近答案的吗?在我的 pom 文件中,我有: org.hibernatehibernate-core4.1.2.Finalorg.hibernate hibernate-entitymanager4.1.2.Final

标签: java spring hibernate jakarta-ee maven


【解决方案1】:
java.lang.NoClassDefFoundError: Lorg/hibernate/cache/CacheProvider;

您的项目中似乎缺少hibernate-core.jar。将其添加到您的 CLASSPATH。 Pick version 与堆栈的其余部分兼容。

【讨论】:

    【解决方案2】:

    尝试将其添加到 pom.xml 中:

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>4.1.2.Final</version>
    </dependency>
    

    【讨论】:

      【解决方案3】:

      我可以看到几个关于同一问题的帖子。您可以检查以下链接,如果这不能解决您的问题,则可以放置用于将 spring 与 hibernate 集成的配置 xml 文件。

      Exception NoClassDefFoundError for CacheProvider

      java.lang.ClassNotFoundException: org.hibernate.cache.CacheProvider exception while integrating spring and hiberate

      【讨论】:

        猜你喜欢
        • 2016-11-04
        • 2020-03-13
        • 1970-01-01
        • 2011-08-09
        • 2012-01-22
        • 2015-12-14
        • 1970-01-01
        • 2012-07-04
        • 1970-01-01
        相关资源
        最近更新 更多