java.lang.IllegalStateException:在 pat 类上检测到 log4j-over-slf4j.jar 和 slf4j-log4j12.jar
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18320146/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.lang.IllegalStateException: Detected both log4j-over-slf4j.jar AND slf4j-log4j12.jar on the class pat
提问by c12
Can anyone tell me the difference between slf4j-log4j and log4j-over-slf4j? Which is more standard to use in a Java web application? I currently have both on the classpath and that is causing a runtime exception as the web server is trying to prevent a StackOverFlowException
from happening.
谁能告诉我 slf4j-log4j 和 log4j-over-slf4j 之间的区别?在 Java Web 应用程序中使用哪个更标准?我目前在类路径上都有,这导致运行时异常,因为 Web 服务器试图防止StackOverFlowException
发生。
Exception:
例外:
java.lang.IllegalStateException:
Detected both log4j-over-slf4j.jar AND slf4j-log4j12.jar on the class path
java.lang.IllegalStateException:
在类路径上检测到 log4j-over-slf4j.jar 和 slf4j-log4j12.jar
采纳答案by FGreg
slf4j-log4jis using log4j as an implementation of slf4j.
slf4j-log4j使用 log4j 作为 slf4j 的实现。
log4j-over-slf4jcauses calls to the log4j API to be 'routed' to slf4j.
log4j-over-slf4j导致对 log4j API 的调用被“路由”到 slf4j。
You cannot use both of these JAR's at the same time.
Both are valid libraries to use and are equally 'standard', it depends on the project.
两者都是可用的有效库,并且同样是“标准”,这取决于项目。
In general, if your project is using log4j already and you don't have the ability to update all of your log4j Loggers to slf4j Loggers; log4j-over-slf4j is a quick fix to be able to start using slf4j immediately.
一般来说,如果您的项目已经在使用 log4j 并且您没有能力将所有 log4j Loggers 更新为 slf4j Loggers;log4j-over-slf4j 是一个快速修复程序,可以立即开始使用 slf4j。
However, if your project is new or does not have an existing logging mechanism and you choose to use slf4j, slf4j-log4j would be the way to go as it is just specifying slf4j should be bound to log4j.
但是,如果您的项目是新项目或没有现有的日志记录机制并且您选择使用 slf4j,那么 slf4j-log4j 将是可行的方法,因为它只是指定 slf4j 应该绑定到 log4j。
That being said, I agree with c12's comment. Stop using log4j and instead use slf4j and logback.
话虽如此,我同意 c12 的评论。停止使用 log4j,而是使用 slf4j 和 logback。
回答by user2665136
in my project , org.slf4j.impl.Log4jLoggerFactory
is in
在我的项目中,org.slf4j.impl.Log4jLoggerFactory
在
activemq-all-5.7.0.jar
not in slf4j-log4j12.jar
不在 slf4j-log4j12.jar
the exception message mislead me
异常消息误导了我