gpt4 book ai didi

java - 将 Spring 3.1 与 Hibernate 4.0.1 一起使用时,如何解决 java.lang.ClassNotFoundException : org. hibernate.util.DTDEntityResolver?

转载 作者:IT老高 更新时间:2023-10-28 13:43:45 25 4
gpt4 key购买 nike

我最近升级到 Hibernate 4.0.1.Final 并且在上下文启动时收到以下错误:

Caused by: java.lang.NoClassDefFoundError: org/hibernate/util/DTDEntityResolver
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2823)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1160)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1655)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1533)
at org.hibernate.cfg.Configuration.reset(Configuration.java:322)
at org.hibernate.cfg.Configuration.<init>(Configuration.java:261)
at org.hibernate.cfg.Configuration.<init>(Configuration.java:265)
at org.hibernate.ejb.Ejb3Configuration.<clinit>(Ejb3Configuration.java:150)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:71)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:257)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
... 65 more
Caused by: java.lang.ClassNotFoundException: org.hibernate.util.DTDEntityResolver
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1688)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1533)

我的配置如下:

<!-- Holding Properties for hibernate -->
<context:property-placeholder location="classpath:hibernate.properties"/>

<!-- Configure annotated beans -->
<context:annotation-config />
<context:component-scan base-package="com.mypackage" />

<!-- Drives transactions using local JPA APIs -->
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref="entityManagerFactory"/>

<!-- Creates a EntityManagerFactory for use with the Hibernate JPA provider -->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
p:dataSource-ref="dataSource"
p:packagesToScan="com.mypackage.entity"
p:jpaVendorAdapter-ref="jpaAdapter"/>

<bean id="jpaAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
p:showSql="true"
p:generateDdl="false"
p:database="MYSQL"
p:databasePlatform="org.hibernate.dialect.MySQL5InnoDBDialect" />

<!-- Deploys datasource-->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="com.mysql.jdbc.Driver"
p:url="jdbc:mysql://localhost:${mysql.port}/?zeroDateTimeBehavior=convertToNull"
p:username="bla"
p:password="bla123"/>

<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />

一些依赖是:

    <dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.5.6-Final</version>
<exclusions>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>ejb3-persistence</artifactId>
</exclusion>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
<exclusions>
<exclusion>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
</exclusion>
<exclusion>
<groupId>jboss</groupId>
<artifactId>javassist</artifactId>
</exclusion>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
</exclusion>
</exclusions>
</dependency>

<properties>
<hibernate.version>4.0.1.Final</hibernate.version>
</properties>

以及spring版本:3.1.0.RELEASE

我假设某些东西正在尝试读取 xml 文件。除了属性文件之外,没有用于 hibernate 的 hibernate xml 配置。当前设置中不存在 Persistence.xml。为什么或谁在寻找 hibernate 4.0.1 中不存在的类?

任何帮助将不胜感激!

最佳答案

根据 Hibernate annotations 3.5 documentation :*

Hibernate 3.5 and onward contains Hibernate Annotations.

您应该删除对 hibernate-annotations 的依赖,并从 hibernate-entitymanager 依赖中删除 exclude。一般来说,你不应该混合依赖包的版本。

* 和 JB Nizet 的评论。

关于java - 将 Spring 3.1 与 Hibernate 4.0.1 一起使用时,如何解决 java.lang.ClassNotFoundException : org. hibernate.util.DTDEntityResolver?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9134436/

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