簡體   English   中英

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

[英]java.lang.NoClassDefFoundError: org/hibernate/util/DTDEntityResolver

運行時出現錯誤,我使用了Spring MVC + Hibernate,spring 3.2版本和hibernate 4版本。

如下所示,模型中的代碼,servlet xml和所有庫的列表都添加到了路徑WEB-INF / lib中。

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

 <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-ٍ所有庫的列表已添加

    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

安慰

  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

我希望有人能找到解決我問題的方法

根據Hibernate注釋3.5文檔:*

Hibernate 3.5及更高版本包含Hibernate注釋。

您應該刪除對hibernate-annotations的依賴 ,並從hibernate-entitymanager依賴中刪除排除項 通常,您不應混用依賴軟件包的版本。

這對我來說是工作。

出現相同的錯誤消息。 從pom刪除對hibernate注釋的依賴(如上面的Prem所述)解決了該問題,Hibernate繼續生成模式(在我的情況下)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM