【问题标题】:NoClassDefFoundError with Spring maven hibernate org/hibernate/ejb/HibernatePersistence in my jUnit Test在我的 jUnit 测试中使用 Spring maven hibernate org/hibernate/ejb/HibernatePersistence 的 NoClassDefFoundError
【发布时间】:2014-04-09 06:46:03
【问题描述】:

当我尝试运行我的 junit 测试(过去可以工作,但神奇地停止了)时,我得到了

Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/hibernate/ejb/HibernatePersistence
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1030)
... 47 more
Caused by: java.lang.NoClassDefFoundError: org/hibernate/ejb/HibernatePersistence
at org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter.<init>(HibernateJpaVendorAdapter.java:57)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

我的 POM 文件确实包含 org.hibernate 依赖项:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>${hibernate.version}</version>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>${hibernate.version}</version>
    <exclusions>
        <exclusion>
            <groupId>cglib</groupId>
            <artifactId>cglib</artifactId>
        </exclusion>
        <exclusion>
            <groupId>dom4j</groupId>
            <artifactId>dom4j</artifactId>
        </exclusion>
    </exclusions>            
</dependency>
<dependency>
    <groupId>org.hibernate.javax.persistence</groupId>
    <artifactId>hibernate-jpa-2.0-api</artifactId>
    <version>1.0.1.Final</version>
</dependency>

我浏览了整个互联网,但找不到解决方案。关于为什么会这样的任何想法?

编辑:通过运行修复问题

mvn 全新安装 -U

Eclipse 不能很好地与 Maven 配合使用 :(

【问题讨论】:

    标签: java spring hibernate maven junit


    【解决方案1】:

    不得不跑

    mvn 全新安装 -U

    mvn eclipse:clean

    mvn eclipse:eclipse

    然后就成功了

    【讨论】:

      猜你喜欢
      • 2012-02-02
      • 2015-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-20
      • 2017-11-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多