Java NoClassDefFoundError:org/hibernate/ejb/HibernatePersistence
我在启动HibernateJavaEndorapter时遇到了NoClassDefFoundErrorJava NoClassDefFoundError:org/hibernate/ejb/HibernatePersistence,java,spring,hibernate,maven,spring-data-jpa,Java,Spring,Hibernate,Maven,Spring Data Jpa,我在启动HibernateJavaEndorapter时遇到了NoClassDefFoundError Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaVendorAdapter' defined in class path resource [META-INF/applicationContext.xml]: Instantiation o
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaVendorAdapter' defined in class path resource [META-INF/applicationContext.xml]: Instantiation of bean failed; nested exception is 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
我检查了这个异常的几个线程,但是没有找到这个异常的根本原因。我认为JPAVendorAdapter的初始化失败了,但不确定原因。可能是我的包依赖项之间或applicationContext.xml中存在不兼容。他们在这里;
xml(仅包含相关部分)
4.0.0
com.canreef
历法
1
战争
历法
UTF-8
1.7
1.7
${project.build.directory}/project
4.0.1.1发布
1.7.0.1发布
4.1.1.1发布
4.1.7.最终版本
2.4.4
${project.basedir}/src/main/lib
org.hibernate
休眠实体管理器
4.3.1.最终版本
org.hibernate
冬眠核心
4.3.0.1最终版本
爪哇
javaeewebapi
7
假如
org.springframework
SpringWebMVC
${org.springframework.version}
org.springframework
春季甲虫
${org.springframework.version}
org.springframework
spring上下文
${org.springframework.version}
org.springframework.data
spring数据jpa
${org.springframework.data.version}
org.springframework
弹簧乐器
${org.springframework.instrument.version}
假如
org.apache.derby
德比客户机
10.11.1.1
org.apache.maven.plugins
maven编译器插件
3.1
1.7
1.7
${annowed.dir}
org.apache.maven.plugins
maven战争插件
2.3
假的
org.apache.maven.plugins
maven依赖插件
2.6
验证
复制
${external.resources}
真的
爪哇
javaee认可的api
7
罐子
未知jars临时回购
NetBeans为无法识别的库和JAR创建的临时存储库。请用正确的依赖项替换此存储库中的依赖项,然后删除此存储库。
文件:${project.basedir}/lib
applicationContext.xml
<?xml version='1.0' encoding='UTF-8' ?>
<!-- was: <?xml version="1.0" encoding="UTF-8"?> -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/data/repository http://www.springframework.org/schema/data/repository/spring-repository.xsd">
<jpa:repositories base-package="com.canreef.calendar"/>
<context:component-scan base-package="com.canreef.calendar"/>
<!-- ADD PERSISTENCE SUPPORT HERE (jpa, hibernate, etc) -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.apache.derby.jdbc.ClientDriver"/>
<property name="url" value="jdbc:derby://localhost:1527/GEAH"/>
<property name="username" value="xxx"/>
<property name="password" value="xxx"/>
</bean>
<bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true" />
<property name="generateDdl" value="true" />
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="persistenceUnitName" value="Test_PU"/>
<property name="jpaVendorAdapter" ref="jpaVendorAdapter"/>
<property name="packagesToScan" value="com.canreef.calendar"/>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
</beans>
如果有人能指出我代码中的错误,我将不胜感激 和你的问题一样?
您缺少一个依赖项:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
</dependency>
org.hibernate
)您依赖于4.1.* 请确保编译的war文件只包含一个org.hibernate.javax.persistence
jar,它应该是2.1。Spring数据jpa将hibernate jpa 2.0与之一起拖动,您应该在pom.xml中特别排除它
最重要的是,您真的需要删除hibernate核心,并且在类路径上只有hibernate entitymanager。确保hibernate内核中也没有其他拖累。您要查找的类仅包含在hibernate entitymanager中
这两件事绝对是你的罪魁祸首。编译并检查JAR是否正确。如果您是从Eclipse中启动Tomcat,请确保部署程序集
中包含所有正确的类路径文件。执行mvneclipse:eclipse
也可能有帮助
基本上,在服务器启动之前,确保所有jar/类都在它们应该位于的位置。按照我说的去做应该已经解决了,但如果没有,肯定会有助于识别罪魁祸首。不,这是POM中的第一个依赖项。这不是问题,你是对的。很抱歉您使用两个版本作为hibernate依赖项(4.3.0和4.3.1)是否有特定的原因?在springframework orm POM中,它提到了hibernate entitymanager 4.2.8。最后,请参见您的观点。问题是公司的公共存储库缺少一些JAR版本,这就是我使用4.3.0和4.3.1的原因。我已成功将4.3.0版本更改为4.2.8,但异常仍然存在。为什么要使用hibernate core和hibernate entitymanager?你应该选择其中一个。我还建议您检查对org.hibernate.javax.persistence
(最好是JPA2.1,它没有spring数据JPA。@Schaka我试图删除hibernate核心,但没有成功。添加hibernate.javax.persistence api 2.1也没有成功。另外请注意,我已经有了hibernate.javax.persistence api 2.1。感谢Schaka给出了精辟的答案。罪犯的头部和头部中枪不耐烦似乎消失了!要了解更多关于依赖项所包含的依赖项,请尝试“mvn dependency:tree”,它帮助我
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
</dependency>