java.lang.NoSuchMethodError: org.apache.log4j.Logger
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23499537/
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.NoSuchMethodError: org.apache.log4j.Logger
提问by Brad Parks
We use ivy to manage a multi project java application, and recently this error started showing up when we do builds. What's causing this?
我们使用ivy 来管理一个多项目的java 应用程序,最近我们在构建时开始出现这个错误。这是什么原因造成的?
采纳答案by Brad Parks
This was fixed by adding the following line to the end of the dependencies section in ivy.xml:
通过在 ivy.xml 中的依赖项部分的末尾添加以下行来修复此问题:
<dependencies>?
<exclude module="log4j-over-slf4j" />
</dependencies>
Why was it an issue?
为什么这是一个问题?
- Looks like the log4j bridge for sjf4j has an incomplete implementation
- This urlexplains it in more detail.
回答by Biswajit_86
It looks like the log4j bridge does not implement the full interface for log4j . If you are still using direct log4j calls, you will need both the slf4j bridge jar and the log4j jar
看起来 log4j 桥没有实现 log4j 的完整接口。如果您仍在使用直接 log4j 调用,您将需要 slf4j bridge jar 和 log4j jar
In your case it looks like you excluded the bridge jar, so all slf4j calls go directly to log4j instead of the bridge.
在您的情况下,您似乎排除了桥接器 jar,因此所有 slf4j 调用都直接转到 log4j 而不是桥接器。
If your code invokes log4j through the xml file , this will work. However if your code programatically invokes log4j initialization this bridge is not going to work
如果您的代码通过 xml 文件调用 log4j,这将起作用。但是,如果您的代码以编程方式调用 log4j 初始化,则此桥接器将无法正常工作
回答by jata shukla
Comment this dependency from the pom.xml
从 pom.xml
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j13</artifactId>
<version>
</dependency>
And add (or keep) the following one:
并添加(或保留)以下内容:
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.12</version>
</dependency>
Wherever you see a compile time error regarding Log4j, add the following import:
无论您在哪里看到有关 Log4j 的编译时错误,请添加以下导入:
import org.apache.log4j.Logger;
回答by Dejazmach
I know this is a very old question but I wanted to share what worked out fine for me. If you have different artifacts of slf4j-log4j* for two projects that are interdependent on each other, for example spring data jpa and spring MVC, this happens. Keep it consistent or even better have a parent pom. In my case I had slf4j-log4j12 on my spring data jpa project and slf4j-log4j13 on my spring MVC one.
我知道这是一个非常古老的问题,但我想分享对我来说很好的方法。如果你有两个相互依赖的项目的 slf4j-log4j* 的不同工件,例如 spring data jpa 和 spring MVC,就会发生这种情况。保持一致,甚至最好有一个父 pom。就我而言,我的 spring 数据 jpa 项目上有 slf4j-log4j12,spring MVC 项目上有 slf4j-log4j13。