Failed to load class "org.slf4j.impl.StaticLogger
最近将Hibernate3.2.6升级为3.5.3,在配置文件等都没变的情况下,启动项目时,出现以下异常
- 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.3的Lib。
提示信息中多次提到SLF4J,google了一下,才发现这是现在的Hibernate使用SLF4J API记录日志,所以在Hibernate的lib中,不再提供Log4J的包,而大部分框架依然使用Log4J记录日志,这样导致了兼容性问题。
解决方法:
下载并添加以下两个包即可解决:
1、log4j-1.2.16.jar
2、slf4j-log4j12-1.5.5.jar
以上两个包文件的版本当然是可以不一样的,但推荐使用最新的