在项目使用开发中, 越来越多使用slf4j进行日志输出. 但是呢?
运行tomcat服务器,其中报错:
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.
2010-11-15 22:41:38 org.apache.catalina.core.StandardContext listenerStart
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in file [D:\MyEclipseWorkspace\misse\WebRoot\WEB-INF\classes\com\liany\misse\misse-spring-global.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
================================================================================
提示信息中多次提到SLF4J,google了一下,使用SLF4J API记录日志,需要在您的应用中,提供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即可
和最新版本可能有差别, 但是解决的方式都相同.