SLF4J:无法在Kafka流中加载类“org.slf4j.impl.StaticLoggerBinder”

问题描述 投票:1回答:1

当我在Kafka Streams中运行像wordcount这样的示例代码时,我得到以下错误:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

我访问了链接:https://www.slf4j.org/codes.html#StaticLoggerBinder并尝试添加其中一个slf4j-nop.jar slf4j-simple.jar,slf4j-log4j12.jar,slf4j-jdk14.jar,如该链接中所述。但它没有帮助。

我在eclipse中看到问题是嵌入式maven版本,但我尝试从控制台创建项目,但我仍遇到同样的问题。

  • Kafka Streams版本 - 0.11.0.0
  • Maven版本 - 3.3.9

有人知道这个问题吗?我接下来的步骤是安装不同的maven版本并尝试它。

maven apache-kafka-streams
1个回答
2
投票

我从maven生产的jar中运行任何Kafka流示例时遇到了同样的问题。在我看来,这是一个简单的编译/测试依赖问题。运行:

mvn dependency:tree

结果显示:

[INFO] +- org.apache.kafka:kafka-clients:jar:1.0.0-cp1:compile
[INFO] |  +- org.lz4:lz4-java:jar:1.4:compile
[INFO] |  +- org.xerial.snappy:snappy-java:jar:1.1.4:compile
[INFO] |  \- org.slf4j:slf4j-api:jar:1.7.25:compile
...
[INFO] +- io.confluent:common-utils:jar:4.0.0:compile
[INFO] \- org.slf4j:slf4j-log4j12:jar:1.7.25:test
[INFO]    \- log4j:log4j:jar:1.2.17:test

所以slf4j-log4j12 jar只包含在测试环境中。我在pom.xml中添加了以下内容

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>1.7.25</version>
</dependency>
<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
</dependency>

重建jar并使用相应的log4j命令行参数运行,这些示例现在都使用日志记录。例如:

java -cp kafka-streams-examples-4.0.0-standalone.jar -Dlog4j.configuration=file:log4j.properties io.confluent.examples.streams.GlobalKTablesExample broker:9092 http://schema_registry:8081
© www.soinside.com 2019 - 2024. All rights reserved.