为 apache Kafka 的 sbt 依赖禁用 SFL4J-Logger

disable SFL4J-Logger for the sbt dependency on apache Kafka

我在使用 kafka 生产者时遇到此错误 API:

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/haifa/.ivy2/cache/org.slf4j/slf4j-log4j12/jars/slf4j-log4j12-1.7.29.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/haifa/.ivy2/cache/ch.qos.logback/logback-classic/jars/logback-classic-0.9.28.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]

在我的 build.sbt 中,我有以下依赖项:

<dependency>
    <groupId>org.apache.kafka</groupId>
    <artifactId>kafka-clients</artifactId>
    <version>2.0.0</version>
      <exclusions>
        <exclusion>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-api</artifactId>
        </exclusion>
     </exclusions>
</dependency>

我发现这个解决方案可以使用 maven 从 Kafka 依赖项中排除 SFL4J。 但是我在使用 sbt 时找不到等效的解决方案。

任何人都可以提供帮助。 谢谢。

Logback 依赖于 slf4j-api。您应该排除 slf4j-log4j12,它会拉出 kafka 使用的 log4j 桥。

您只需将 exclude 添加到 sbt 依赖项的末尾

How to exclude commons-logging from a scala/sbt/slf4j project?