我在equinox环境中面临jpa + hibernate的问题。我正在异常
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter#53308cd' defined in OSGi resource[classpath:/spring/gdl-commons-db-jpa-context.xml|bnd.id=177|bnd.sym=gdl-open-domain]: 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
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1037)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:983)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:487)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:271)
... 34 common frames omitted
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)
... 38 common frames omitted
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)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148)
... 40 common frames omitted
请在下面找到关于我的罐子详情
com.springsource.javassist-3.15.0.GA.jar
hibernate-core-3.3.2.GA.jar
com.springsource.javax.transaction-1.1.0.jar
hibernate-core-4.1.9.Final.jar
com.springsource.org.hibernate-4.1.0.Final.jar
com.springsource.org.hibernate.annotations.common-3.3.0.ga.jar
hibernate-entitymanager-3.4.0.GA.jar
com.springsource.org.hibernate.annotations.common-4.0.1.Final.jar
hibernate-entitymanager-4.1.9.Final.jar
hibernate-annotations-3.4.0.GA.jar
hibernate-jpa-2.0-api-1.0.1.Final.jar
spring-data-commons-1.6.0.RELEASE.jar
hibernate-validator-4.0.2.GA.jar
我的manifest.mf是
Import-Package: org.springframework.data.jpa.domain.support;version="[
1.3,2)",org.springframework.data.jpa.repository;version="[1.3,2)",org
.springframework.data.repository;version="[1.5,2)",javax.sql,org.apac
he.commons.pool;version="[1.5,2)",org.apache.commons.pool.impl;versio
n="[1.5,2)",org.springframework.orm.jpa.persistenceunit,org.springfra
mework.core.io,org.springframework.core.type.classreading,org.springf
ramework.core.io.support,org.springframework.core.type.filter,org.spr
ingframework.util,org.springframework.core.type,javax.persistence;version="1.0.1";jpa
="2.0",javassist.util.proxy;resolution:=optional,org.
hibernate,org.springframework.orm.jpa,org.hibernate.ejb,org.springfra
mework.orm.jpa.vendor,org.springframework.dao.annotation,org.springfr
amework.jmx.export.assembler,org.springframework.jmx.support,org.spri
ngframework.beans.factory.config,org.springframework.beans.factory.as
pectj,org.hibernate.proxy,org.springframework.aop.aspectj.autoproxy,o
rg.springframework.aop.interceptor,org.hibernate.ejb.connection,javax.persistence.criteria
Meta-Persistence: META-INF/persistence.xml
Spring-Context: spring/*.xml
请帮我解决这个类没找到异常。
谢谢,
gopy
编辑:
我现在面临的问题是我正在使用hibernate-release-4.3.7.Final,
好的,让我解释一下我的项目结构,并告诉我缺少的地方,
目前我们的系统在一个jar文件中有一个war文件。所以我需要迁移到osgi并取出所有与业务相关的jar来设置模块概念。
所以最初我拿出一些重要的库并转换成捆绑。
让我们说,
Bundle_A是一个主要包,里面包含许多第三方依赖,包括我们的应用程序相关库library_b,library_c等。
从Bundle_A
导入所有库 Bundle-ClassPathlibrary_b,library_c有自己的spring.xml,其中一些配置是从Bundle_A
加载的library_b,spring.xml有JPARepositoryImpl和配置,我们在Bundle_A中有一些存储库也引用了library_a实现。似乎我得到异常,如JPARepositoryImpl类未正确加载。找不到类。
请在下面找一些例外,
nested exception is java.lang.NoClassDefFoundError: com.domain.jpa.impl.MyRepositoryFactoryBean not found from bundle [My Platform Domain (My--domain)]
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [org.springframework.data.jpa.domain.support.AuditingEntityListener] for bean with name 'org.springframework.data.jpa.domain.support.AuditingEntityListener' defined in null: problem with class file or dependent class; nested exception is java.lang.NoClassDefFoundError: org.springframework.data.jpa.domain.support.AuditingEntityListener not found from bundle [My Platform Domain (My--domain)]
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [com.domain.jpa.impl.MyRepositoryFactoryBean] for bean with name 'communicationSettingRepository' defined in null: problem with class file or dependent class; nested exception is java.lang.NoClassDefFoundError: com.domain.jpa.impl.MyRepositoryFactoryBean not found from bundle [My Platform Domain (My--domain)]
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [com.domain.jpa.impl.MyRepositoryFactoryBean]
.. .. ..等等
这是一个很大的例外,因为我有很多存储库,例如communicationSettingRepository,所以它打印所有的存储库名称,如
Error loading class [com.domain.jpa.impl.MyRepositoryFactoryBean] for bean with name 'repository' defined in null
例外结束是
Caused by: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:715)
at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:522)
at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:348)
at sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:283)
at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:117)
at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:70)
at java.lang.Class.initAnnotationsIfNecessary(Class.java:3271)
at java.lang.Class.initAnnotationsIfNecessary(Class.java:3278)
at java.lang.Class.getAnnotation(Class.java:3219)
at java.lang.Class.isAnnotationPresent(Class.java:3232)
at org.hibernate.annotations.common.reflection.java.JavaAnnotationReader.isAnnotationPresent(JavaAnnotationReader.java:50)
at org.hibernate.annotations.common.reflection.java.JavaXAnnotatedElement.isAnnotationPresent(JavaXAnnotatedElement.java:60)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.syncAnnotatedClasses(Configuration.java:3780)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1411)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1846)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:852)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:845)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:398)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:844)
at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:152)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:67)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:288)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1571)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1509)
... 31 common frames omitted
希望你们能猜出真正的问题吗?请帮我解决这个问题。
答案 0 :(得分:9)
hibernate-entitymanager-4.1.9.Final.jar应该是缺少的类。您的类路径中有多个版本的hibernate库。 3.x和4.x.我建议你下载最新的hibernate version并用当前的classpath jar替换它们。
另外,旁注org/hibernate/ejb/HibernatePersistence
已弃用。如果您使用的是JPA标准,org.hibernate.jpa.HibernatePersistenceProvider
是正确的持久性提供程序。
答案 1 :(得分:0)
确保在pom.xml中设置包装参数; Web项目之战。
<packaging>war</packaging>
。 Web服务器需要将此参数设置为war,以便它可以依赖于它正确地部署您的应用程序。