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

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


当前回答

根据SLF4J官方文档

加载org.slf4j.impl.StaticLoggerBinder类失败 时报告此警告消息 org.slf4j.impl。无法装入StaticLoggerBinder类 内存。当找不到合适的SLF4J绑定时就会发生这种情况 在类路径上。放置一个(且只有一个)slf4j-nop.jar文件, Slf4j-simple.jar、slf4j-log4j12.jar、slf4j-jdk14.jar或 类路径上的Logback-classic.jar应该可以解决这个问题。

只需将这个jar和slf4j api.jar一起添加到类路径中就可以完成工作。 祝你好运

其他回答

这里有相当多的答案建议向maven pom文件添加slf4j-simple依赖项。您可能需要检查最新的版本。

在https://mvnrepository.com/artifact/org.slf4j/slf4j-simple 您将找到SLF4J简单绑定的最新版本。选择一个最适合你的版本(2021-07年的1.7.32仍然是2021-10年的稳定版本),并将其包含到你的pom.xml中。

为了您的方便,这里显示了一些依赖项-但当您阅读本文时,它们可能不是最新的!

2021-08测试版

<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
   <groupId>org.slf4j</groupId>
   <artifactId>slf4j-simple</artifactId>
   <version>2.0.0-alpha5</version>
 </dependency>

2019年2月的测试版

<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-simple</artifactId>
    <version>1.8.0-beta4</version>
</dependency>

稳定版2021-07

<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
   <groupId>org.slf4j</groupId>
   <artifactId>slf4j-simple</artifactId>
   <version>1.7.32</version>
</dependency>

由于下面的评论,我删除了范围测试部分。

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

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

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

将文件slf4j-log4j12-1.6.4.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.

当我在我的库中使用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包