복붙노트

[SPRING] 중첩 예외는 java.lang.NoClassDefFoundError : org / hibernate / ejb / HibernatePersistence입니다.

SPRING

중첩 예외는 java.lang.NoClassDefFoundError : org / hibernate / ejb / HibernatePersistence입니다.

나는 Spring 3.2, Hibernate 4와 함께 JPA 2.0을 영속성 제공자로 설정하려고 시도하고있다. Weblogic 10.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" />

보시다시피 entitymanager jar 파일을 가져옵니다.

제공 할 수있는 도움은 크게 감사하겠습니다.

감사!

해결법

  1. ==============================

    1.ClassNotFoundException이 아닌 java.lang.NoClassDefFoundError를 얻었으므로 아마도 일종의 클래스 로딩 문제 일 것입니다.

    ClassNotFoundException이 아닌 java.lang.NoClassDefFoundError를 얻었으므로 아마도 일종의 클래스 로딩 문제 일 것입니다.

    웹 애플리케이션 라이브러리 (WEB-INF / lib), 응용 프로그램 서버에서 이미 사용할 수있는 JAR을 가져 오기 때문에 종종 발생합니다.

    귀하의 경우, 나는 최대 절전 모드 - jpa - 2.0 - api.jar 용의자.

    다음 두 가지 방법을 시도해보십시오.

  2. ==============================

    2.확실히 일부 오래된 버전이나 사용하지 않는 지금은 최대 절전 항아리가 귀하의 lib 폴더에 존재합니다. 내 경우에는 최대 절전 모드 - 주석 - x.x.x.jar이었다.

    확실히 일부 오래된 버전이나 사용하지 않는 지금은 최대 절전 항아리가 귀하의 lib 폴더에 존재합니다. 내 경우에는 최대 절전 모드 - 주석 - x.x.x.jar이었다.

    내 lib에서이 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 만 넣으십시오.

    다른 이전의 최대 절전 모드 버전의 항아리가 있으면 제거하고 최신 항아리를 넣으십시오.

  3. ==============================

    3.이 메이븐 저장소를 기반으로하면 최대 절전 모드 관리자 -4.2.2. 최종 버전이 존재하지 않습니다. 4.2.1.Final도 사용하십시오. 여기에 의존성에 대한 최대 절전 모드 핵심 정보와 같은 다른 최대 절전 모드 종속성을 추가해야한다고 생각합니다.

    이 메이븐 저장소를 기반으로하면 최대 절전 모드 관리자 -4.2.2. 최종 버전이 존재하지 않습니다. 4.2.1.Final도 사용하십시오. 여기에 의존성에 대한 최대 절전 모드 핵심 정보와 같은 다른 최대 절전 모드 종속성을 추가해야한다고 생각합니다.

  4. from https://stackoverflow.com/questions/17053668/nested-exception-is-java-lang-noclassdeffounderror-org-hibernate-ejb-hibernatep by cc-by-sa and MIT license