2012-07-07 93 views
5

當我開始我的Spring MVC的項目我有以下異常:錯誤創建SessionFactory的

javax.servlet.ServletException: Servlet.init() for servlet appServlet threw exception 

而且最重要的事情是根本原因:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 
'sessionFactory' defined in ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml]: 
Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError:  
org/hibernate/cfg/EJB3DTDEntityResolver 

我已經看過了這個類:http://docs.jboss.org/hibernate/orm/3.5/api/org/hibernate/cfg/EJB3DTDEntityResolver.html這裏http://search.maven.org/#search%7Cga%7C1%7Cfc%3Aorg.hibernate.cfg.EJB3DTDEntityResolver 我發現它是hibernate-annotations的一部分。但我有一些Hibernate的依賴條件在我POM.xml文件:

<!-- Hibernate --> 
    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-core</artifactId> 
     <version>4.1.4.Final</version> 
    </dependency> 
    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-annotations</artifactId> 
     <version>3.5.6-Final</version> 
    </dependency>  
    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-validator</artifactId> 
     <version>4.3.0.Final</version> 
    </dependency> 
    <dependency> 
     <groupId>org.hibernate.common</groupId> 
     <artifactId>hibernate-commons-annotations</artifactId> 
     <version>4.0.1.Final</version> 
    </dependency> 
    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-envers</artifactId> 
     <version>4.1.4.Final</version> 
    </dependency> 

我不知道這有什麼錯我的項目做。一般來說,當我在我的Servlet調度器中聲明瞭這個異常時:

<!-- Hibernate session factory -->  
<beans:bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> 

    <beans:property name="dataSource"> 
     <beans:ref bean="dataSource" /> 
    </beans:property> 

    <beans:property name="hibernateProperties"> 
     <beans:props> 
      <beans:prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</beans:prop> 
      <beans:prop key="hibernate.show_sql">true</beans:prop> 
     </beans:props> 
    </beans:property> 

    <beans:property name="annotatedClasses"> 
     <beans:list> 
      <beans:value>hutter.pl.dao.Users</beans:value>       
     </beans:list> 
    </beans:property> 
</beans:bean> 

<beans:bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> 
    <beans:property name="sessionFactory" ref="sessionFactory" /> 
</beans:bean> 
<!-- Hibernate session factory end --> 

你能給我一些建議嗎?

回答

9

hibernate-annotationshibernate-coresince 3.6

+1

都在我的一部分。你建議我可能會導致衝突? – woyaru 2012-07-07 08:03:08

+1

當我從依賴關係中刪除hibernate-annotations時,問題已經消失。謝謝。 – woyaru 2012-07-07 10:10:27

相關問題