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

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


当前回答

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

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

其他回答

我在一个项目Struts2+Spring中工作。所以它需要一个依赖项slf4j-api-1.7.5.jar。

如果我运行这个项目,我会得到这样的错误

加载类“org.slf4j.impl.StaticLoggerBinder”失败

我通过添加slf4j-log4j12-1.7.5.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-log4j12-1.6.4.jar放到类路径中就可以了。

您需要在类路径中添加以下jar文件:slf4j-simple-1.6.2.jar。如果你没有,请下载。请参考http://www.slf4j.org/codes.html#multiple_bindings

在Websphere案例中,您有一个较老版本的slf4j-api.jar, 1.4.x。或1.5。X躺在某个地方。您在tcServer上观察到的行为,即故障转移到NOP,发生在slf4j 1.6.0及更高版本上。确保在所有平台上使用slf4j-api-1.6.x.jar,并且在类路径中没有放置slf4j-api的旧版本。