永続性プロバイダーとしてHibernate4を使用してSpring3.2、JPA2.0を構成しようとしています。アプリケーションをWeblogic10.3.5にデプロイしようとすると、次のエラーが発生します(サイズが原因で省略されています)。
<Jun 11, 2013 1:04:51 PM EDT> <Error> <org.springframework.web.context.ContextLoader> <BEA-000000> <Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/spring/spring-config.xml]: Cannot create inner bean 'org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter#ade8fd6' of type [org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter] while setting bean property 'jpaVendorAdapter'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter#ade8fd6' defined in ServletContext resource [/WEB-INF/spring/spring-config.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
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.Java:230)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.Java:117)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.Java:1245)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.Java:1010)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.Java:472)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.Java:409)
at Java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.Java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.Java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.Java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.Java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.Java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.Java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.Java:423)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.Java:728)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.Java:380)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.Java:255)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.Java:199)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.Java:45)
at weblogic.servlet.internal.EventsManager$FireContextListenerAction.run(EventsManager.Java:481)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.Java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.Java:120)
at weblogic.servlet.internal.EventsManager.notifyContextCreatedEvent(EventsManager.Java:181)
at weblogic.servlet.internal.WebAppServletContext.preloadResources(WebAppServletContext.Java:1872)
at weblogic.servlet.internal.WebAppServletContext.start(WebAppServletContext.Java:3153)
at weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.Java:1508)
at weblogic.servlet.internal.WebAppModule.start(WebAppModule.Java:482)
at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.Java:425)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.Java:52)
at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.Java:119)
at weblogic.application.internal.flow.ScopedModuleDriver.start(ScopedModuleDriver.Java:200)
at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.Java:247)
at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.Java:425)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.Java:52)
at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.Java:119)
at weblogic.application.internal.flow.StartModulesFlow.activate(StartModulesFlow.Java:27)
at weblogic.application.internal.BaseDeployment$2.next(BaseDeployment.Java:636)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.Java:52)
at weblogic.application.internal.BaseDeployment.activate(BaseDeployment.Java:205)
at weblogic.application.internal.EarDeployment.activate(EarDeployment.Java:58)
at weblogic.application.internal.DeploymentStateChecker.activate(DeploymentStateChecker.Java:161)
at weblogic.deploy.internal.targetserver.AppContainerInvoker.activate(AppContainerInvoker.Java:79)
at weblogic.deploy.internal.targetserver.BasicDeployment.activate(BasicDeployment.Java:184)
at weblogic.deploy.internal.targetserver.BasicDeployment.activateFromServerLifecycle(BasicDeployment.Java:361)
at weblogic.management.deploy.internal.DeploymentAdapter$1.doActivate(DeploymentAdapter.Java:51)
at weblogic.management.deploy.internal.DeploymentAdapter.activate(DeploymentAdapter.Java:200)
at weblogic.management.deploy.internal.AppTransition$2.transitionApp(AppTransition.Java:30)
at weblogic.management.deploy.internal.ConfiguredDeployments.transitionApps(ConfiguredDeployments.Java:240)
at weblogic.management.deploy.internal.ConfiguredDeployments.activate(ConfiguredDeployments.Java:169)
at weblogic.management.deploy.internal.ConfiguredDeployments.deploy(ConfiguredDeployments.Java:123)
at weblogic.management.deploy.internal.DeploymentServerService.resume(DeploymentServerService.Java:180)
at weblogic.management.deploy.internal.DeploymentServerService.start(DeploymentServerService.Java:96)
at weblogic.t3.srvr.SubsystemRequest.run(SubsystemRequest.Java:64)
at weblogic.work.ExecuteThread.execute(ExecuteThread.Java:209)
at weblogic.work.ExecuteThread.run(ExecuteThread.Java:178)
これが私のpom.xmlです:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.version>3.2.3.RELEASE</spring.version>
<struts2.version>2.3.14</struts2.version>
</properties>
<dependencies>
<!-- Java Servlet provided jars -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
<!-- Oracle -->
<dependency>
<groupId>Oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>1.0</version>
</dependency>
<!-- Struts 2 -->
<dependency>
<groupId>org.Apache.struts</groupId>
<artifactId>struts2-convention-plugin</artifactId>
<version>${struts2.version}</version>
</dependency>
<dependency>
<groupId>org.Apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>${struts2.version}</version>
</dependency>
<dependency>
<groupId>org.Apache.struts</groupId>
<artifactId>struts2-spring-plugin</artifactId>
<version>${struts2.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Hibernate Entity Manager -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.2.2.Final</version>
</dependency>
<!-- Spring 3 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
これが私のspring-config.xmlです:
<context:property-placeholder location="classpath:db.properties" />
<context:component-scan base-package="com.ceic" />
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${db.driver}" p:url="${db.url}" p:username="${db.username}"
p:password="${db.password}" />
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
p:dataSource-ref="dataSource" p:packagesToScan="com.ceic">
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
p:showSql="true" p:databasePlatform="org.hibernate.dialect.Oracle10gDialect" />
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref="entityManagerFactory" />
<tx:annotation-driven transaction-manager="transactionManager" />
<bean
class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
ご覧のとおり、entitymanagerjarファイルを取得しています。
提供できる助けをいただければ幸いです。
ありがとう!
Java.lang.NoClassDefFoundError
(ClassNotFoundException
ではなく)を取得するため、おそらく何らかのクラスローディングの問題です。
多くの場合、アプリケーションサーバーですでに利用可能なJARをwebappライブラリ(WEB-INF/lib
)にインポートすることが原因です。
あなたの場合、私はhibernate-jpa-2.0-api.jar
を疑っています。
試すべき2つのことがあります:
依存関係からhibernate-jpa-2.0-api.jar
を除外します。
OR
<prefer-web-inf-classes>
ファイルにweblogic.xml
を追加します。
確かにいくつかの古いバージョンまたは使用されていない現在、休止状態のjarがlibフォルダーに存在します。私の場合、それはhibernate-annotations-x.x.x.jarでした。
このhibernate-annotations-x.x.x.jarをライブラリから削除しました。
Hibernate-commons-annotations-x.x.x.jarを使用している場合は、jarの上に置く必要はありません。同じ問題に直面していて、hibernate-annotations-x.x.x.jarを削除してサーバーを再起動すると、エラーがなくなりました。 hibernate-commons-annotations-x.x.x.jarのみを配置します。
他の古いHibernateバージョンのjarを検索し、ある場合はそれを削除して最新のものを配置します。