当我开始我的Spring MVC项目时,我有以下例外:
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的一部分。但我的POM.xml
文件中有一些Hibernate依赖:
<!-- 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 Dispatcher中声明这个异常时发生了这个异常:
<!-- 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 -->
你能给我一些建议吗?