解决Failed to load class "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.  
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

 使用hiberate新建库的错误代码, 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即可

 

文章出自:http://zhoujingxian.iteye.com/blog/657079

你可能感兴趣的:(static)