Deployed Tomcat 7 WAR application throws NoClassDefFoundError error
I am working on a hello-world type of web application. I am using Eclipse Helios as my IDE, Maven 2 to handle dependencies, and a locally run Tomcat 7 server to deploy and test. The application is Spring MVC based and uses Hibernate for data management.
I can successfully package the project into a WAR file. When I deploy the WAR in Tomcat, the following error is reported in the logs:
SEVERE: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateSessionFactory' defined in ServletContext resource [/WEB-INF/spring-servlet.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.cfg.AnnotationConfiguration at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409) Etc...
I checked to be sure that the correct dependency is included in my POM, and it is:
<dependency>
<groupId>org.hibernate</g开发者_如何学编程roupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.4.0.GA</version>
<type>jar</type>
<optional>false</optional>
</dependency>
I checked to see that the packaged WAR file has the required JAR file which has the class mentioned (org.hibernate.cfg.AnnotationConfiguration) in the error and it does:
./Tomcat 7/webapps/helloworld/WEB-INF/lib/hibernate-annotations-3.4.0.GA.jar
Based on this information, I figure that this might be a classpath configuration issue. From the documentation I've read on Tomcat 7, Tomcat should be able to utilize the JAR files in "/WEB-INF/lib" folder. Any one know if I may have skipped a step in configuration of Tomcat in order for it to recognize the JAR files in the lib folder of a webapp?
I realize this is generic advice, but I've had similar problems like this in the past with both Tomcat and Jetty and it was because I had multiple/wrong versions of some dependency. I'd start by using the M2Eclipse POM editor in Eclipse and click on "Dependency Hierarchy" and carefully review all of the transitive dependencies.
精彩评论