ClassCastException Log4jLoggerFactory LoggerContex

筆尖的痕發表於2016-05-25

http://my.oschina.net/u/249914/blog/192987

 xception 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
今天除錯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,所以留下了它。

相關文章