Tuesday, August 30, 2011

Error creating bean with name 'org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping

ERROR: org.springframework.web.servlet.DispatcherServlet - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory' defined in ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration

Suggestions/Solutions While setting up environment for a project  I started getting the above error. I was using Springsourcetool and despite  all the JAR's in my projects's classpath I was getting this error.  I googled and there were different posts with different suggestions. Most of them suggested adding these JARS to WEB-INF/lib folder

spring-core.JAR(suitable version 3+ in my case)
spring-orm.JAR(suitable version 3+ in my case)
spring-mvc.JAR(suitable version 3+ in my case)

Allthough I was using Spring Source Tool and the abve JARs should not have mattered. So,None of the above worked for me, However carefully comparing the end of the error I found they were different from each other, In my case it says nested exception is java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration

looking at the error it was pretty obvious that i needed my hibernate3.jar . Allthough it was added in my projects class path it had to be added to WEB-INF/lib
I added the
hibernate3.jar to WEB-INF/lib folder and the error was resolved.

hope it would be helpful to someone, If you still get the same error after trying all the above mentioned JARs you need to look at the error carefully and see what might be missing


No comments:

Post a Comment