【问题标题】:Error Failed to load class "org.slf4j.impl.StaticLoggerBinder" Apache Kafka错误无法加载类“org.slf4j.impl.StaticLoggerBinder”Apache Kafka
【发布时间】:2019-07-01 22:01:59
【问题描述】:

当我构建 Java 类并运行时,我遇到了无法加载类“org.slf4j.impl.StaticLoggerBinder”的错误。我正在学习“Apache Kafka 快速入门指南”一书的课程。 Java 项目被编译为 gradle 项目。我已经在 build.gradle 文件中包含了“slf4j-simple”,但错误仍然存​​在。

我正在输入 gradle jar 来构建 .jar 文件。

错误:

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.

还有 build.gradle:

apply plugin: 'java'
apply plugin: 'application'

sourceCompatibility = '1.8'

mainClassName = 'monedero.ProcessingEngine'

repositories {
   mavenCentral()
}

version = '0.1.0'

dependencies {
   compile group: 'org.apache.kafka', name: 'kafka_2.12', version: 
   '2.0.0'
   compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', 
   version: '2.9.7'
   testCompile group: 'org.slf4j', name: 'slf4j-simple', version:  
   1.6.1'
             }

jar {
    manifest {
       attributes 'Main-Class': mainClassName
    } from {
       configurations.compile.collect {
          it.isDirectory() ? it : zipTree(it)
    }
}
exclude "META-INF/*.SF"
exclude "META-INF/*.DSA"
exclude "META-INF/*.RSA"
}

【问题讨论】:

  • 这与 Kafka 无关,也不是错误。阅读提供的链接
  • 嗨!我已经打开了链接,并且在 stackoverflow 中阅读了其他类似的问题,但对我不起作用。
  • 这不是错误,只是令人讨厌的日志消息。您的程序仍会运行,只是不会得到日志输出。

标签: java gradle slf4j


【解决方案1】:

您需要将 testCompile 更改为 compile 才能让主应用程序加载这些类。

【讨论】:

  • 我现在就去试试!
  • simple 是一个实际的日志实现。
猜你喜欢
  • 2017-02-19
  • 2012-08-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-18
  • 2017-07-24
  • 2021-05-08
相关资源
最近更新 更多