簡體   English   中英

使用log4j 1.2.17發出“此SLF4J版本需要log4j版本1.2.12”的警告

[英]“This version of SLF4J requires log4j version 1.2.12” warning with log4j 1.2.17

我有一個Java Maven項目,其依賴項包括slf4j及其log4j adapter 我根據http://mvnrepository.comlog4jslf4j-log4j12slf4j-api的版本管理為最新版本,尤其是1.2.17的log4j版本遠遠超過1.2.12,但仍然出現錯誤

SLF4J: This version of SLF4J requires log4j version 1.2.12 or later. 
    See also http://www.slf4j.org/codes.html#log4j_version 

我完全不清楚。

我的Maven依賴性管理如下所示:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.apache.jena</groupId>
            <artifactId>apache-jena-libs</artifactId>
            <type>pom</type>
            <version>2.10.0</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.5</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.5</version>
        </dependency>
    </dependencies>
</dependencyManagement>

如何擺脫警告?

PS:我也得到了java.lang.NoSuchMethodError: org.apache.log4j.Logger.isTraceEnabled()

PPS:由於您的評論,我記得該程序有一個“ lib”文件夾,Maven並未將它包含在類路徑中,但Eclipse本身並未將其包含在類路徑中,因此沖突的依賴項必須位於該文件夾中。 抱歉,我完全忘了我猜這是將Maven與lib文件夾混合的錯誤。 我想我必須嘗試將盡可能多的庫轉換為Maven依賴項。 盡管奇怪的是,即使我編輯“ Order and Export”以將Maven依賴項放在頂部,問題仍然會發生。

StaticLoggerBinder -log4j12中的StaticLoggerBinder代碼很早就加載了,它執行檢查以確定log4j中的TRACE級別是否可用。 這是代碼:

private StaticLoggerBinder() {
  loggerFactory = new Log4jLoggerFactory();
  try {
    Level level = Level.TRACE;
  } catch (NoSuchFieldError nsfe) {
    Util.report("This version of SLF4J requires log4j version 1.2.12 or later."+
                " See also http://www.slf4j.org/codes.html#log4j_version");
  }
}

對我來說似乎很氣密。

可能是某些其他依賴項正在引入或實際上嵌入了log4j的早期版本。 某些* -standalone.jar文件可以做到這一點。

在部署時檢查您的類路徑。 您是否要在應用服務器中進行部署? 服務器類路徑上是否有較舊版本的log4j? 在Java認可的路徑中?

您應該在<dependency>之外定義<dependencyManagement> ,如下所示:-

<dependencyManagement>
    <dependencies>
    ...
    </dependencies>
</dependencyManagement>
<dependencies>
    <dependency>
        <groupId>org.apache.jena</groupId>
        <artifactId>apache-jena-libs</artifactId>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
    </dependency>
</dependencies>

有關更多信息,請參見“依賴機制簡介:依賴管理 ”。

希望對您有所幫助。

將注釋更改為答案,因為它似乎可以解決問題。

這是一個類加載器問題,maven正確構建了它,但缺少依賴項。 您可以嘗試將缺少的依賴項提供給Maven嗎? 否則,建議您查看Eclipse特定的依賴項。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM