ClassCastException Log4jLoggerFactory LoggerContex

今天调试web项目,使用Spring+各种组件。
其中用到了slf4j-core,slf4j-simple,slf4j-api,logback-classic,slf4j-log4j12。。。
运行后报一下 错误


SEVERE: Exception sending context initialized event to listener instance of class ch.qos.logback.ext.spring.web.LogbackConfigListener
java.lang.ClassCastException: org.slf4j.impl.Log4jLoggerFactory cannot be cast to ch.qos.logback.classic.LoggerContext
at ch.qos.logback.ext.spring.LogbackConfigurer.initLogging(LogbackConfigurer.java:72)
at ch.qos.logback.ext.spring.web.WebLogbackConfigurer.initLogging(WebLogbackConfigurer.java:142)
at ch.qos.logback.ext.spring.web.LogbackConfigListener.contextInitialized(LogbackConfigListener.java:54)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)


java.lang.NullPointerException
at ch.qos.logback.ext.spring.LogbackConfigurer.shutdownLogging(LogbackConfigurer.java:104)
at ch.qos.logback.ext.spring.web.WebLogbackConfigurer.shutdownLogging(WebLogbackConfigurer.java:187)
at ch.qos.logback.ext.spring.web.LogbackConfigListener.contextDestroyed(LogbackConfigListener.java:49)
at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4831)
at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5478)
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:160)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)

at java.lang.Thread.run(Thread.java:744)


解决方案:
把slf4j-simple,slf4j-log4j12引用去掉,因为他们都实现了org.slf4j.impl.StaticLoggerBinder。
logback-classic也实现了org.slf4j.impl.StaticLoggerBinder,因为我要使用logback,所以留下了它。

你可能感兴趣的:(log4j,logback)