gpt4 book ai didi

java - 泽西 + Spring + hibernate

转载 作者:行者123 更新时间:2023-12-01 12:50:53 25 4
gpt4 key购买 nike

我尝试使用 Jersey/Spring/Hibernate 部署应用程序,每次我尝试部署它时都会抛出此异常:

    SEVERE: Context initialization failed
java.lang.NoClassDefFoundError: Lorg/hibernate/cache/CacheProvider;
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2570)
at java.lang.Class.getDeclaredFields(Class.java:1903)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:372)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessMerge
...

我的 spring 配置 xml 如下所示:

<context:component-scan base-package="intellidom.reader"/>

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/intellidom" />
<property name="username" value="root" />
<property name="password" value="" />
</bean>

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.connection.pool_size">0</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
</props>
</property>
</bean>

<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

当 sessionFactory 和 transactionManager 被注释时,部署工作正常。这段代码有什么问题?

编辑:pom.xml

<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.intellidom</groupId>
<artifactId>IntelliDOM</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>IntelliDOM</name>
<url>http://maven.apache.org</url>
<dependencies>

<!--string parsing-->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.0</version>
</dependency>

<!--Hibernate-->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.1.4.FINAL</version>
</dependency>

<!--MySQL-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.30</version>
<scope>runtime</scope>
</dependency>

<!-- Spring 3 dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>

<!--Jersey-->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.8</version>
</dependency>

<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-spring</artifactId>
<version>1.8</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</exclusion>
</exclusions>
</dependency>

</dependencies>
<build>
<finalName>IntelliDOM</finalName>
</build>

最佳答案

Spring 3.0.5 中不支持 Hibernate 4。您需要使用Hibernate 3或升级Spring版本。您的 pom.xml 表示您正在使用 Hibernate 4,但 xml 配置适用于 Hibernate 3。我相信对 Hibernate 4 的支持是在 Spring 3.1.0 中首次引入的。因此,要么更改 pom.xml 以使用 Hibernate 3 和 Spring 3.0.5,要么使用 Hibernate 4 和至少 Spring 3.1.0,并将所有包更改为 hibernate4 而不是 hibernate3 在您的 xml 配置文件中,例如:org.springframework.orm.hibernate4.LocalSessionFactoryBean

关于java - 泽西 + Spring + hibernate ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24221836/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com