在我的jUnit测试中使用Spring maven hibernate org / hibernate / ejb / HibernatePersistence的NoClassDefFoundError

时间:2014-03-06 14:44:14

标签: java spring hibernate maven junit

当我尝试运行我的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 clean install -U

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

1 个答案:

答案 0 :(得分:0)

必须跑

  

mvn clean install -U

     

mvn eclipse:clean

     

mvn eclipse:eclipse

然后它起作用了