복붙노트

[SPRING] Hibernate 4.0.1에서 Spring 3.1을 사용할 때 java.lang.ClassNotFoundException : org.hibernate.util.DTDEntityResolver를 어떻게 해결할 수 있습니까?

SPRING

Hibernate 4.0.1에서 Spring 3.1을 사용할 때 java.lang.ClassNotFoundException : org.hibernate.util.DTDEntityResolver를 어떻게 해결할 수 있습니까?

나는 최근에 최대 절전 모드 4.0.1로 업그레이드했다. 최종 버전이며 컨텍스트 시작시 다음과 같은 오류가 발생한다 :

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>

그리고 스프링 버전 : 3.1.0.RELEASE

나는 뭔가가 XML 파일을 읽으려고한다고 가정하고있다. 프로퍼티 파일 이외의 hibernate에 대한 hibernate xml 설정은 없다. 현재 설정에는 Persistence.xml이 없습니다. 왜 또는 누가 최대 절전 모드 4.0.1에 존재하지 않는 클래스를 찾고 있습니까?

어떤 도움이라도 대단히 감사하겠습니다!

해결법

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

    1.Hibernate annotations 3.5 문서마다 : *

    Hibernate annotations 3.5 문서마다 : *

    hibernate-annotations에 대한 의존성을 제거하고, hibernate-entitymanager 의존성으로부터 exclude를 제거해야한다. 일반적으로 종속 패키지 버전을 혼합해서는 안됩니다.

    *와 JB Nizet의 코멘트.

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

    2.이 의존성을 pom.xml에 추가하십시오.

    이 의존성을 pom.xml에 추가하십시오.

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>tck-utils-api</artifactId>
        <version>0.9.1</version>
    </dependency>
    
  3. ==============================

    3.나는 지금이 문제가 내 의존성에있어 괜찮아.

    나는 지금이 문제가 내 의존성에있어 괜찮아.

    <properties>
        <spring.version>4.0.5.RELEASE</spring.version>
        <junit.version>4.11</junit.version>
        <jdk.version>1.6</jdk.version>
    </properties>
    
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    
        <!-- Spring dependencies -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</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-web</artifactId>
            <version>${spring.version}</version>
        </dependency>
    
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>
    
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${spring.version}</version>
        </dependency>
    
        <!-- Servlet -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>3.0-alpha-1</version>
        </dependency>
    
        <!-- JSTL -->
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
    
    
        <!-- Apache Commons Upload -->
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.2.2</version>
        </dependency>
    
        <!-- Apache Commons Upload -->
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>1.3.2</version>
        </dependency>
    
        <!-- MYSQL dependency -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.6</version>
        </dependency>
    
        <!-- Hibernate -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.3.5.Final</version>
        </dependency>
    
        <!-- If using JPA (2), add: -->
    
    
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.5.6</version>
        </dependency>
    
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.5.6</version>
        </dependency>
    
        <dependency>
            <groupId>c3p0</groupId>
            <artifactId>c3p0</artifactId>
            <version>0.9.1.2</version>
        </dependency>
    
        <dependency>
            <groupId>org.javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.18.1-GA</version>
        </dependency>
    
    </dependencies>
    
  4. ==============================

    4.나는 같은 문제에 직면했다. hibernate annotation에 대한 의존성을 제거한 후에, 나는 내 코드를 성공적으로 실행할 수 있었다.

    나는 같은 문제에 직면했다. hibernate annotation에 대한 의존성을 제거한 후에, 나는 내 코드를 성공적으로 실행할 수 있었다.

  5. from https://stackoverflow.com/questions/9134436/how-can-i-resolve-java-lang-classnotfoundexception-org-hibernate-util-dtdentity by cc-by-sa and MIT license