gpt4 book ai didi

java - 获取异常 org.apache.logging.slf4j.SLF4JLoggerContext 无法转换为 org.apache.logging.log4j.core.LoggerContext

转载 作者:IT老高 更新时间:2023-10-28 20:36:52 32 4
gpt4 key购买 nike

我的代码使用 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/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com