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

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


当前回答

我在使用Java 9库的Spring-boot-2应用程序时也遇到了类似的问题。

在我的pom.xml中添加以下依赖项为我解决了这个问题:

<dependency>
    <groupId>com.googlecode.slf4j-maven-plugin-log</groupId>
    <artifactId>slf4j-maven-plugin-log</artifactId>
    <version>1.0.0</version>
</dependency>

其他回答

我在使用Java 9库的Spring-boot-2应用程序时也遇到了类似的问题。

在我的pom.xml中添加以下依赖项为我解决了这个问题:

<dependency>
    <groupId>com.googlecode.slf4j-maven-plugin-log</groupId>
    <artifactId>slf4j-maven-plugin-log</artifactId>
    <version>1.0.0</version>
</dependency>

我也犯了同样的错误。我已经在我的本地开发中配置了slf4j-api, slf4j-log4j12和log4j。所有配置都很好,但是我从mvnrepository复制的slf4j-log4j12依赖项有测试范围<范围>测试</范围>。当我把这一切都是好的。

有时愚蠢的错误会让我们崩溃;)

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

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

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

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

有时我们应该看到来自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的相应代码。