我的应用程序将部署在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。

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


当前回答

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

预览代码

(如果您使用的是弹性搜索版本< 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,并删除了这个错误。

其他回答

简单地添加到你的pom.xml:

<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-simple</artifactId>
  <version>1.7.21</version>
</dependency>
     <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.7.21</version>
    </dependency>

将上述依赖项放在pom.xml文件中

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

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

SLF4j是各种日志记录框架的抽象。因此,除了slf4j之外,您还需要在类路径中包含任何日志框架,如log4j或logback(等等)。 要有一个想法,请参考http://logback.qos.ch/manual/introduction.html的第一步

可以使用相同的版本来解决这个问题。我试过了,而且解决了

< >的依赖 < groupId > org.slf4j < / groupId > < artifactId > slf4j-api < / artifactId > <版本> 1.7.5 > < /版本 < / >的依赖 < >的依赖 < groupId > org.slf4j < / groupId > < artifactId > slf4j-log4j12 < / artifactId > <版本> 1.7.5 > < /版本 < / >的依赖