当前位置: 首页 > 知识库问答 >
问题:

noClassDefFounderRor:org/hibernate/ejb/hibernatePersistence

司徒耀
2023-03-14
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
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.canreef</groupId>
    <artifactId>Calendar</artifactId>
    <version>1.0</version>
    <packaging>war</packaging>

    <name>Calendar</name>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>

        <org.springframework.version>4.0.1.RELEASE</org.springframework.version>
        <org.springframework.data.version>1.7.0.RELEASE</org.springframework.data.version>
        <org.springframework.instrument.version>4.1.1.RELEASE</org.springframework.instrument.version>
        <org.hibernate.version>4.1.7.Final</org.hibernate.version>
        <jackson.version>2.4.4</jackson.version>
        <external.resources>${project.basedir}/src/main/lib</external.resources>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>4.3.1.Final</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.3.0.Final</version>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>        
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>        
        <!-- Added-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${org.springframework.version}</version>
        </dependency> 
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-jpa</artifactId>
            <version>${org.springframework.data.version}</version>

        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-instrument</artifactId>
            <version>${org.springframework.instrument.version}</version>
            <scope>provided</scope>
        </dependency>        
        <dependency>
            <groupId>org.apache.derby</groupId>
            <artifactId>derbyclient</artifactId>
            <version>10.11.1.1</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${external.resources}</outputDirectory>
                            <silent>true</silent>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>javax</groupId>
                                    <artifactId>javaee-endorsed-api</artifactId>
                                    <version>7.0</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <repositories>
        <repository>
            <id>unknown-jars-temp-repo</id>
            <name>A temporary repository created by NetBeans for libraries and jars it could not identify. Please replace the dependencies in this repository with correct ones and delete this repository.</name>
            <url>file:${project.basedir}/lib</url>
        </repository>
    </repositories>
</project>

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>

如果有人能指出我代码中的错误,真的很感激。

共有1个答案

韩靖琪
2023-03-14

请确保编译后的war文件只包含一个org.hibernate.javax.persistenceJAR,应该是2.1。Spring-data-jpa拖动了hibernate-jpa2.0,您应该在pom.xml中特别排除它。

最重要的是,您确实需要删除hibernate-core,在类路径上只保留hibernate-entitymanager。确保hibernate-core也没有其他东西拖动。您要查找的类仅包含在Hibernate-EntityManager中。

这两件事绝对是你的罪魁祸首。编译并检查正确的JAR。如果从Eclipse中启动Tomcat,请确保部署程序集中包含所有正确的类路径文件。执行MVN eclipse:eclipse也可能有所帮助。

 类似资料:
  • 问题内容: 我在pom.xml中定义了依赖项 我在 C:/User/.m2/repository/org/hibernate/hibernate-commons- annotations/3.3.0.ga中* 有上述jar * 我在hibernate.cfg.xml中配置了会话工厂和数据源,同时尝试在我的main方法中构建配置: 我得到: 我试过直接在我的构建路径以及WEB-INF / lib中添

  • 问题内容: 我的项目使用spring3 jpa(hibernate),但是我在使用Hibernate Persistence类时遇到了问题……所以我无法正确创建我的entityManager,并且问题不断发生…… 我相信问题在我的pom.xml文件中!(如果这不是问题,那么也许在我的应用程序COntext.xml中?不这么认为,但他知道…) 这是pom.xml 现在错误输出: 您可以看到它是一个嵌

  • 问题内容: 关于将由完整的Java EE应用程序服务器(例如GlassFish)提供服务的Java EE Web应用程序,这是最佳的 ORM 解决方案吗? EJB 3 或 Hibernate 3 为什么? 问题答案: 这两个完全不同。 是一个组件模型,与ORM直接无关。它确实有助于轻松管理事务,并使您可以轻松地从JPA访问实体管理器,JPA是Java EE中的标准化ORM解决方案。 (3)确实是一

  • 我在部署EJB3.1应用程序时遇到了一个问题。下面是堆栈跟踪: 12:37:05,400信息[org.jboss.as.server.deployment](MSC服务线程1-3)JBAS015877:86MS 12:37:05,405信息[org.jboss.as.controller](DeploymentScanner-Threads-2)JBAS014774:服务状态报告JBAS01477

  • 问题内容: 我正在尝试运行此处给出的示例图块示例。 以下是我的POM.xml: 当我尝试运行示例时,抛出以下错误: 任何想法? 为此,我花了30分钟的时间进行谷歌搜索,但找不到可能的解决方案。 请帮我… 问题答案: 您已经包括了对SLF4J API的依赖关系,这是您在应用程序中用于日志记录的内容,但是您还必须包括一个实现实际日志记录功能的实现。 例如,要通过Log4J登录,您可以添加以下依赖项:

  • 如能提供任何帮助,我将不胜感激。 谢谢!