简体   繁体   English

java.lang.NoSuchMethodError:org.apache.log4j.Logger

[英]java.lang.NoSuchMethodError: org.apache.log4j.Logger

We use ivy to manage a multi project java application, and recently this error started showing up when we do builds. 我们使用常春藤来管理多项目java应用程序,最近这个错误在我们构建时开始出现。 What's causing this? 是什么导致了这个?

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? 为什么这是一个问题?

It looks like the log4j bridge does not implement the full interface for log4j . 看起来log4j桥没有实现log4j的完整接口。 If you are still using direct log4j calls, you will need both the slf4j bridge jar and the log4j jar 如果您仍在使用直接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. 如果您的代码通过xml文件调用log4j,这将起作用。 However if your code programatically invokes log4j initialization this bridge is not going to work 但是,如果您的代码以编程方式调用log4j初始化,则此桥将无法工作

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. 如果对于彼此相互依赖的两个项目有不同的slf4j-log4j *工件,例如spring数据jpa和spring MVC,就会发生这种情况。 Keep it consistent or even better have a parent pom. 保持一致,甚至更好地拥有父母pom。 In my case I had slf4j-log4j12 on my spring data jpa project and slf4j-log4j13 on my spring MVC one. 在我的情况下,我在我的spring数据jpa项目上有slf4j-log4j12,在我的spring MVC上有slf4j-log4j13。

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;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.ClassNotFoundException: org.apache.log4j.Logger - java.lang.ClassNotFoundException: org.apache.log4j.Logger 引起原因:java.lang.ClassNotFoundException:org.apache.log4j.Logger - Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger Weblogic java.lang.ClassNotFoundException:org.apache.log4j.Logger-Maven项目 - Weblogic java.lang.ClassNotFoundException: org.apache.log4j.Logger - Maven project Java中“ org.apache.log4j.Logger”的奇怪行为 - Strange behavior of “org.apache.log4j.Logger” in Java ClassNotFoundException: org.apache.log4j.Logger - ClassNotFoundException: org.apache.log4j.Logger NoClassDefFoundError::org.apache.log4j.Logger - NoClassDefFoundError: : org.apache.log4j.Logger java.lang.ClassNotFoundException: org.apache.log4j.Logger - Eclipse still searching for old class after upgrading from version 1 to 2.17.0 - java.lang.ClassNotFoundException: org.apache.log4j.Logger - Eclipse still searching for old class after upgrading from version 1 to 2.17.0 java.lang.SecurityException:类“ org.apache.log4j.Logger”与同一包中其他类的信任级别不匹配 - java.lang.SecurityException: class “org.apache.log4j.Logger” does not match trust level of other classes in the same package java.lang.NoSuchMethodError:org.apache.logging.log4j.core.lookup.MapLookup.toMap - java.lang.NoSuchMethodError: org.apache.logging.log4j.core.lookup.MapLookup.toMap log4j error java.lang.NoSuchMethodError: org.apache.log4j.spi.LoggingEvent.getTimestamp()J - log4j error java.lang.NoSuchMethodError: org.apache.log4j.spi.LoggingEvent.getTimestamp()J
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM