作者热门文章
- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我的代码使用 apache-log4j-2.0.2 非常简单:
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
public class Log4jtest {
static Logger log =Logger.getLogger(Log4jtest.class);
public static void main(String[] args) {
BasicConfigurator.configure();
log.debug("This is debug message");
}
}
但是我遇到了这样的异常:
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.lang.ClassCastException: org.apache.logging.slf4j.SLF4JLoggerContext cannot be cast to org.apache.logging.log4j.core.LoggerContext``
at org.apache.log4j.Logger.getLogger(Logger.java:41)
at Log4jtest.<clinit>(Log4jtest.java:11)
为什么异常来自一个简单的程序?
最佳答案
Remove below jar's from class path and it should fix the issue -
log4j-to-slf4j-2.0.2.jar
log4j-to-slf4j-2.0.2-sources.jar
log4j-slf4j-impl-2.0.2.jar
log4j-slf4j-impl-2.0.2-sources.jar
I was able to replicate and fix the issue after downloading apache-log4j-2.0.2 from http://www.apache.org/dyn/closer.cgi/logging/log4j/2.0.2/apache-log4j-2.0.2-bin.zip.
关于java - 获取异常 org.apache.logging.slf4j.SLF4JLoggerContext 无法转换为 org.apache.logging.log4j.core.LoggerContext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25891737/
我是一名优秀的程序员,十分优秀!