java.lang.NoClassDefFoundError: org/hibernate/util/DTDEntityResolver

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19296677/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 15:47:40  来源:igfitidea点击:

java.lang.NoClassDefFoundError: org/hibernate/util/DTDEntityResolver

javaspringhibernateservletsspring-mvc

提问by SW Engineer

I get error when i run , i used Spring MVC + Hibernate, spring 3.2 release and hibernate 4 release.

运行时出错,我使用了 Spring MVC + Hibernate、spring 3.2 版本和 hibernate 4 版本。

As below my code in model , servlet xml , and list of all libraries were added to path WEB-INF/lib .

如下所示,我的模型、servlet xml 和所有库列表中的代码已添加到路径 WEB-INF/lib 中。

1- FEP_Health_Model

1- FEP_Health_Model

package Models;

import org.hibernate.HibernateException;
import org.hibernate.SessionFactory;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.AnnotationConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

public class FEP_Health_Model {
   @Autowired
   private SessionFactory factory;

   public FEP_Health_Model()
  { 
   System.out.print("Hello Spring MVC with Hibernate");
       try{
              configureSessionFactory();
   }catch(Throwable ex){
       System.err.println("Failed to create sessionFactory object." + ex); throw new    
               ExceptionInInitializerError(ex);
   }
  }
  @Transactional
  public void test()
  {
   Session session = factory.openSession();
   Transaction trans = null;
   try{
      trans = session.beginTransaction();
      /*
       Some Code 
      */
      trans.commit();
   }catch(Throwable ex){

   }finally{
       session.close();
   }
   }
   private void configureSessionFactory() throws HibernateException {
    AnnotationConfiguration configuration = new AnnotationConfiguration();
    configuration.configure().addAnnotatedClass(FepEnergyData.class);       
    factory = configuration.buildSessionFactory();
   }
}

2- springmvc-servlet.xml

2- springmvc-servlet.xml

 <beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:tx="http://www.springframework.org/schema/tx" 
 xmlns:context="http://www.springframework.org/schema/context"
 xmlns:mvc="http://www.springframework.org/schema/mvc"
 xsi:schemaLocation="http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
 http://www.springframework.org/schema/mvc
 http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
 http://www.springframework.org/schema/context
 http://www.springframework.org/schema/context/spring-context-3.2.xsd
 http://www.springframework.org/schema/aop 
 http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
 http://www.springframework.org/schema/tx 
 http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">

 <context:component-scan base-package="Controllers"></context:component-scan>
 <context:component-scan base-package="Models"></context:component-scan>
 <context:annotation-config />


 <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/JSP/" />
    <property name="suffix" value=".jsp" />
 </bean>


<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
   <property name="url"     
   value="jdbc:sqlserver://127.0.0.1:1433;databaseName=AECMDMS_TEST;instanceName=SQLEXPRESS;"/>
   <property name="username" value="user"/>
   <property name ="password" value="123" />
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="configLocation">
        <value>/META-INF/hibernate.cfg.xml</value>
    </property>

    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect"> org.hibernate.dialect.SQLServer2008Dialect</prop>
            <prop key="hibernate.show_sql">true</prop>
        </props>
    </property>
</bean>

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

   <tx:jta-transaction-manager transaction-manager="transactionManager"/>
</beans>


3- ?list of all libraries have been added

3- ? 添加了所有库的列表

    commons-digester3-3.2.jar   
    commons-io-2.4.jar
    commons-logging-1.1.3.jar
    dom4j-1.6.1.jar
    ejb3-persistence.jar
    hibernate-annotations-3.5.6-Final.jar
    hibernate-commons-annotations-4.0.2.Final.jar
    hibernate-core-4.2.5.Final.jar
    hibernate-envers-4.2.5.Final.jar
    hibernate-jpa-2.0-api-1.0.1.Final.jar
    javassist-3.15.0-GA.jar
    jboss-logging-3.1.0.GA.jar
    jboss-transaction-api_1.1_spec-1.0.1.Final.jar
    log4j.jar
    org.osgi.core-4.3.1.jar
    org.springframework.aop-3.2.0.RELEASE.jar
    org.springframework.beans-3.2.0.RELEASE.jar
    org.springframework.context-3.2.0.RELEASE.jar
    org.springframework.core-3.2.0.RELEASE.jar
    org.springframework.jdbc-3.2.0.RELEASE.jar
    org.springframework.orm-3.2.0.RELEASE.jar
    org.springframework.transaction-3.2.0.RELEASE.jar
    org.springframework.web.servlet-3.2.0.RELEASE.jar
    org.springframework.web-3.2.0.RELEASE.jar
    spring-webmvc-3.2.0.RELEASE.jar
    spring-asm-3.2.0.M1.jar 
    spring-tx-3.2.0.RELEASE.jar
    slf4j-api-1.7.5.jar
    slf4j-log4j12-1.7.5.jar
    slf4j-simple-1.7.5.jar
    sqljdbc4.jar
    xalan-2.7.1.jar
    xercesImpl.jar
    xml-apis.jar

Console

安慰

  SEVERE: StandardWrapper.Throwable
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name     
  'sessionFactory' defined in ServletContext resource [/WEB-INF/FEP_Health-servlet.xml]:    
  Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError:   
  org/hibernate/util/DTDEntityResolver

i hope anybody find solution for My problem

我希望有人为我的问题找到解决方案

回答by Zoo Zoo

Per the Hibernate annotations 3.5 documentation:*

根据 Hibernate annotations 3.5 文档:*

Hibernate 3.5 and onward contains Hibernate Annotations.

Hibernate 3.5 及更高版本包含 Hibernate Annotations。

You should remove the dependency on hibernate-annotations, and remove the excludes from the hibernate-entitymanager dependency. Generally, you should not mix versions of dependent packages.

您应该删除对 hibernate-annotations 的依赖,并从 hibernate-entitymanager 依赖项中删除排除项。通常,您不应混合依赖包的版本。

This is work for me.

这对我来说是工作。

回答by user577736

Had the same error message. Removing the dependency on hibernate-annotations from the pom (as described by Prem above) solved the issue and Hibernate went on to generate the schema (in my case).

有同样的错误信息。从 pom 中删除对 hibernate-annotations 的依赖(如上面的 Prem 所述)解决了这个问题,Hibernate 继续生成模式(在我的情况下)。