我的应用程序将部署在tcServer和WebSphere 6.1上。这个应用程序使用ehCache,因此需要slf4j作为依赖项。 因此,我将slf4j-api.jar (1.6) jar添加到war文件包中。

应用程序在tcServer中正常工作,除了以下错误:

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.

然而,当我在WebSphere中部署时,我得到了一个java.lang.NoClassDefFoundError: org.slf4j.impl.StaticLoggerBinder。

同时伴有加载类“org.slf4j.impl.StaticMDCBinder”失败

我已经检查了两个应用服务器的类路径,没有其他slf4j jar。

有人知道这里会发生什么吗?


当前回答

在将logback-classic升级到最新版本:1.4.5之后,我遇到了这个问题SLF4J:未能加载类“org.slf4j.impl”。StaticLoggerBinder”。logback-classic: 1.4。X没有org.slf4j.impl类。StaticLoggerBinder,这就是问题所在。

供您参考:slf4j-api 2.0。x将不再搜索StaticLoggerBinding。详情请参阅https://www.slf4j.org/faq.html#changesInVersion200。

其他回答

有时我们应该看到来自SLF4J警告的说明:请参阅http://www.slf4j.org/codes.html#StaticLoggerBinder以了解更多详细信息。

当在类路径上找不到合适的SLF4J绑定时,就会发生这种情况

您可以搜索此警告产生的原因。 将*slf4j-nop.jar、slf4j-simple.jar、slf4j-log4j12.jar、slf4j-jdk14.jar或logback-classic.jar*中的一个jar添加到类路径中应该可以解决问题。

compile "org.slf4j:slf4j-simple:1.6.1"

例如,将上述代码添加到构建中。Gradle或maven项目的pom.xml的相应代码。

我也遇到过类似的问题,通过以下方法解决了问题:

文件->项目结构… 模块->依赖项 从Maven ->搜索:slf4j.nop 单击最新版本-> Apply

我没有添加任何依赖项,我只是改变了我使用它们的方式。

预览代码

(如果您使用的是弹性搜索版本< 7.0,则取消注释此代码)

IndexRequest indexRequest = new IndexRequest(
  "twitter",
  "tweets",
  id // this is to make our consumer idempotent
).source(record.value(), XContentType.JSON);

当前代码

IndexRequest indexRequest = new IndexRequest("tweets")
  .source(record.value(), XContentType.JSON)
  .id(id); // this is to make our consumer idempotent

我使用bulkrequest,并删除了这个错误。

当我得到以下错误时,我陷入了这个问题:

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.

当我在我的库中使用slf4j-api-1.7.5.jar。

尽管我尝试了整个建议的补充jar,如slf4j-log4j12-1.7.5.jar, slf4j-simple-1.7.5,但错误消息仍然存在。当我将slf4j-jdk14-1.7.5.jar添加到java库中时,这个问题最终得到了解决。

在http://www.slf4j.org/download.html上获得整个slf4j包

对我来说,问题是: 在使用Hibernate时,我看到它已经使用了slf4j,而且它已经在我的类路径中,所以我决定使用它。 下一步-为slf4j添加imlementor,所以我添加到maven:

<dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-jdk14</artifactId>
        <version>1.7.25</version>
</dependency>

但是它错误地失败了!SLF4J:加载类“org.slf4j.impl.StaticLoggerBinder”失败

解决方案是: Hibernate的slf4j依赖项是版本1.7.26,我添加了小版本依赖项1.7.25。当我修复了这个,一切都好了