如何修复log4j中的“ NoSuchMethodError”错误

时间:2019-04-05 18:22:57

标签: java elasticsearch log4j

我正在开发一个使用Elasticsearch的Java应用程序。我在Java中使用elasticsearch api。我收到NoSuchMethodError错误:

  

java.lang.NoSuchMethodError:   org.apache.logging.log4j.Logger.trace(Ljava / lang / String; Ljava / lang / Object;)V

我已经包含了我的pom文件

 <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.elasticsearch.client</groupId>
        <artifactId>transport</artifactId>
        <version>5.4.2</version>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>5.4.2</version>
    </dependency>
    <dependency>
        <groupId>org.mongodb</groupId>
        <artifactId>mongo-java-driver</artifactId>
        <version>3.2.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>2.3</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.3</version>
    </dependency>
    <dependency>
        <groupId>commons-configuration</groupId>
        <artifactId>commons-configuration</artifactId>
        <version>1.10</version>
    </dependency>

    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.3</version>
    </dependency>
</dependencies>

1 个答案:

答案 0 :(得分:0)

请检查类路径上的Log4j依赖项。对于Elasticsearch 5.4.x,您需要Log4j 2.8.2(API和核心),而不是2.3。参见https://www.elastic.co/guide/en/elasticsearch/client/java-api/5.4/_log4j_2_logger.html