关于SLF4J Exception异常处理

Failed to load class org.slf4j.impl.StaticLoggerBinder

This error is reported when the org.slf4j.impl.StaticLoggerBinder class could not be loaded into memory. This happens when no appropriate SLF4J binding could be found on the class path. Placing one (and only one) of slf4j-nop.jar, slf4j-simple.jar, slf4j-log4j12.jar, slf4j-jdk14.jar or logback-classic.jar on the class path should solve the problem.

As of SLF4J version 1.6, in the absence of a binding, SLF4J will default to a no-operation (NOP) logger implementation.

You can download SLF4J bindings from the project download page.

 

使用hiberate新建库的错误代码 <embed height="15" width="14" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" allowscriptaccess="always" quality="high" flashvars="clipboard=SLF4J%3A%20Failed%20to%20load%20class%20%22org.slf4j.impl.StaticLoggerBinder%22.%0ASLF4J%3A%20See%20http%3A%2F%2Fwww.slf4j.org%2Fcodes.html%23StaticLoggerBinder%20for%20further%20details.%0AException%20in%20thread%20%22main%22%20java.lang.NoClassDefFoundError%3A%20org%2Fslf4j%2Fimpl%2FStaticLoggerBinder%0A%09at%20org.slf4j.LoggerFactory.getSingleton(LoggerFactory.java%3A223)%0A%09at%20org.slf4j.LoggerFactory.bind(LoggerFactory.java%3A120)%0A%09at%20org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java%3A111)%0A%09at%20org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java%3A269)%0A%09at%20org.slf4j.LoggerFactory.getLogger(LoggerFactory.java%3A242)%0A%09at%20org.slf4j.LoggerFactory.getLogger(LoggerFactory.java%3A255)%0A%09at%20org.hibernate.cfg.Configuration.%3Cclinit%3E(Configuration.java%3A165)%0A%09at%20com.bjsxt.usermgr.util.ExportDB.main(ExportDB.java%3A11)%0ACaused%20by%3A%20java.lang.ClassNotFoundException%3A%20org.slf4j.impl.StaticLoggerBinder%0A%09at%20java.net.URLClassLoader%241.run(URLClassLoader.java%3A200)%0A%09at%20java.security.AccessController.doPrivileged(Native%20Method)%0A%09at%20java.net.URLClassLoader.findClass(URLClassLoader.java%3A188)%0A%09at%20java.lang.ClassLoader.loadClass(ClassLoader.java%3A306)%0A%09at%20sun.misc.Launcher%24AppClassLoader.loadClass(Launcher.java%3A276)%0A%09at%20java.lang.ClassLoader.loadClass(ClassLoader.java%3A251)%0A%09at%20java.lang.ClassLoader.loadClassInternal(ClassLoader.java%3A319)%0A%09...%208%20more" src="http://zhoujingxian.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf">
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

 

转载于:https://www.cnblogs.com/birlt/archive/2011/12/08/2280098.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值