Failed to load class org.slf4j.impl.StaticLoggerBinder
2010-05-12 10:06
- SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
- SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
- Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder
- at org.slf4j.LoggerFactory.getSingleton(LoggerFactory.java:223)
- at org.slf4j.LoggerFactory.bind(LoggerFactory.java:120)
- at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:111)
- at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:269)
- at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:242)
- at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:255)
- at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:165)
- at com.bjsxt.usermgr.util.ExportDB.main(ExportDB.java:11)
- Caused by: java.lang.ClassNotFoundException: org.slf4j.impl.StaticLoggerBinder
- at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
- at java.security.AccessController.doPrivileged(Native Method)
- at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
- at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
- at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
- at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
- at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
- ... 8 more
hibernate工程里面使用的是hibernate3.5的Lib。
提示信息中多次提到SLF4J,google了一下,才发现这是现在的Hibernate使用SLF4J API记录日志,所以在Hibernate的lib中,不再提供Log4J的包,而大部分框架依然使用Log4J记录日志,这样导致了兼容性问题。
解决办法,两步:
一、在编译路径中添加Log4J的包,比如我一直在用的log4j-1.2.8.jar;
二、再添加一个叫做slf4j-log4j12-1.5.11.jar的包进行转换,注意到这里的log4j12,可能对应的是log4j 1.2版本。解决!
补充:
SLF4J官方下载:http://www.slf4j.org/download.html
下载对应版本后加压找到slf4j-log4j12-XX.jar即可
加上hibernate所有必要包后,还包如下错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in file [F:\gcmworkspace\Framwo\WebContent\WEB-INF\classes\applicationContext-hibernate.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
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:883)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:839)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
需要在classpath中添加另一个包:slf4j-nop-1.5.2.jar
麻烦的是需要单独下载.....
java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details