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

java.lang.NoClassDefFoundError:org/hibernate/util/dtdentialResolver,java,spring,hibernate,servlets,spring-mvc,Java,Spring,Hibernate,Servlets,Spring Mvc,我运行时出错,我使用了SpringMVC+Hibernate、Spring3.2版本和Hibernate4版本 如下所示,我在模型中的代码、servlet xml和所有库的列表都添加到了路径WEB-INF/lib中 1-FEP\U健康模式 package Models; import org.hibernate.HibernateException; import org.hibernate.SessionFactory; import org.hibernate.Session; impor

我运行时出错,我使用了SpringMVC+Hibernate、Spring3.2版本和Hibernate4版本

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

1-FEP\U健康模式

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();
   }
}
 <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>
2-springmvcservlet.xml

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();
   }
}
 <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>
控制台

  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 annotations 3.5文档找到我的问题的解决方案

:*

Hibernate 3.5及更高版本包含Hibernate注释

您应该删除对hibernate注释的依赖关系,并从hibernate entitymanager依赖关系中删除排除项。通常,您不应该混合使用依赖包的版本


这是我的工作。

根据Hibernate annotations 3.5文档:*

Hibernate 3.5及更高版本包含Hibernate注释

您应该删除对hibernate注释的依赖关系,并从hibernate entitymanager依赖关系中删除排除项。通常,您不应该混合使用依赖包的版本


这是我的工作。

有相同的错误消息。
从pom中删除对hibernate注释的依赖(如上面Prem所述)解决了这个问题,hibernate继续生成模式(在我的例子中)。

有相同的错误消息。
从pom中删除对hibernate注释的依赖(如上面Prem所述)解决了这个问题,hibernate继续生成模式(在我的例子中)。

可能重复@maksimov Great!非常感谢你!让它成为一个解决方案,让我来评分:)你可以+1原始答案,我不想因为重复问题的重复答案而获得荣誉。@maksimov的可能重复太棒了!非常感谢你!让它成为一个解决方案,让我来评分:)你可以+1原始答案,我不想因为重复问题的重复答案而获得荣誉。