我的应用程序将部署在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是底层日志框架(如log4j、logback、java.util.logging)的门面。

为了连接底层框架,slf4j使用了绑定。

log4j - slf4j-log4j12-1.7.21.jar java.util.logging – slf4j-jdk14-1.7.21.jar etc

如果没有绑定jar,就会抛出上述错误。您可以下载这个jar并将其添加到类路径中。

对于maven依赖,

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

除了slf4j-log4j12-1.7.21.jar之外,这个依赖项还将slf4j-api-1.7.21.jar以及log4j-1.2.17.jar拉到您的项目中

参考:http://www.slf4j.org/manual.html

其他回答

将文件slf4j-log4j12-1.6.4.jar放到类路径中就可以了。

他们的官网给出了解决方案:

Failed to load class org.slf4j.impl.StaticLoggerBinder This warning message is reported when the org.slf4j.impl.StaticLoggerBinder class could not be loaded into memory. This happens when no appropriate SLF4J binding could be found on the class path. Placing one (and only one) of slf4j-nop.jar slf4j-simple.jar, slf4j-log4j12.jar, slf4j-jdk14.jar or logback-classic.jar on the class path should solve the problem. SINCE 1.6.0 As of SLF4J version 1.6, in the absence of a binding, SLF4J will default to a no-operation (NOP) logger implementation. If you are responsible for packaging an application and do not care about logging, then placing slf4j-nop.jar on the class path of your application will get rid of this warning message. Note that embedded components such as libraries or frameworks should not declare a dependency on any SLF4J binding but only depend on slf4j-api. When a library declares a compile-time dependency on a SLF4J binding, it imposes that binding on the end-user, thus negating SLF4J's purpose.

解决方案:我已经添加到我的项目中使用intellij的maven研究,我选择了slf4j-jdk14.jar。

我知道这篇文章有点老了,但以防其他人遇到这个问题:

将slf4j-jdk14-X.X.X.jar添加到CLASSPATH中(其中X.X.X为版本号,例如slf4j-jdk14-1.7.5.jar)。

HTH 彼得

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

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

在payara 5.191上遇到了同样的问题

Jcl-over-slf4j和slf4j-log4j12一起解决了这个问题

<properties>
  <slf4j.version>1.7.29</slf4j.version>
</properties>

<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-api</artifactId>
  <version>${slf4j.version}</version>
  <type>jar</type>
</dependency> 

<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>jcl-over-slf4j</artifactId>
  <version>${slf4j.version}</version>
</dependency>        

<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-log4j12</artifactId>
  <version>${slf4j.version}</version>
</dependency>