I received the following error while running a Spring and Hibernate application
Based on the stack trace, I realized that since I am using Hibernate to version 3.3.x. In Hibernate 3.3.x (after some reading around) I came to know that they replaced apache commons-logging with slf4j maybe because of issues with commons-logging.
SLF4J requires you to use one of the binding jars. And you may need to download it from their website. Example: if you are using log4j, put slf4j-log4j12-.jar together with slf4j-api.jar.
Since I am using maven, I introduced the following lines in pom.xml
This resolved the issue.
Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.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/slf4j/impl/StaticLoggerBinder
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder
Caused by: java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder
at org.slf4j.LoggerFactory.(LoggerFactory.java:60)
at org.hibernate.cfg.Configuration.(Configuration.java:151)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.class$(LocalSessionFactoryBean.java:158)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.(LocalSessionFactoryBean.java:158)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:85)
...
Based on the stack trace, I realized that since I am using Hibernate to version 3.3.x. In Hibernate 3.3.x (after some reading around) I came to know that they replaced apache commons-logging with slf4j maybe because of issues with commons-logging.
SLF4J requires you to use one of the binding jars. And you may need to download it from their website. Example: if you are using log4j, put slf4j-log4j12-
Since I am using maven, I introduced the following lines in pom.xml
<dependency>
<groupid>org.slf4j</groupid>
<artifactid>slf4j-log4j12</artifactid>
<version>1.6.1</version>
</dependency>
This resolved the issue.