SLF4J:无法加载类"org.slf4j.impl.StaticLoggerBinder"

JJ1*_*180 547 java websphere slf4j

我的应用程序将部署在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.
Run Code Online (Sandbox Code Playgroud)

但是,当我在WebSphere中部署时,我得到了一个java.lang.NoClassDefFoundError: org.slf4j.impl.StaticLoggerBinder.

我检查了两个应用程序服务器的类路径,没有其他的slf4j jar.

有没有人有任何想法可能会发生在这里?

pra*_*ann 476

我在WebSphere 6.1中遇到了同样的问题.正如Ceki指出的那样,WebSphere正在使用大量的罐子,其中一个指向旧版本的slf4j.

No-Op回滚只发生在slf4j -1.6+上,因此任何比这更旧的东西都会抛出异常并停止部署.

SLf4J网站上有一个解决此问题的文档.我跟着它,并添加slf4j-simple-1.6.1.jar到我的应用程序slf4j-api-1.6.1.jar,我已经有.

这解决了我的问题.希望它可以帮助那些有这个问题的人.

  • 嘿你MAVEN用户:http://mvnrepository.com/artifact/org.slf4j/slf4j-simple/1.6.2 (141认同)
  • 我的评论不值得自己回答,但要确保范围不只是设置为测试。(<scope>test</scope>; 不要这样做) (4认同)
  • 是的,错误也在这里提到 - http://www.slf4j.org/manual.html但我现在得到一个新的错误 - 引起:java.lang.ClassNotFoundException:org.apache.commons.logging.LogFactory (3认同)
  • “正如 Ceki 指出的那样,WebSphere 正在使用大量 jar,其中一个指向旧版本的 slf4j。” - Maven 处理依赖关系就到此为止了!真是笑话。 (2认同)
  • 我使用1.7并且有同样的问题.我添加了slf4j-simple-1.7.jar,现在问题解决了. (2认同)

Igo*_*kov 335

这是为那些从谷歌搜索来到这里的人.

如果您使用maven,只需添加以下内容即可

   <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-api</artifactId>
       <version>1.7.5</version>
   </dependency>
   <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-log4j12</artifactId>
       <version>1.7.5</version>
   </dependency>
Run Code Online (Sandbox Code Playgroud)

要么

   <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-api</artifactId>
       <version>1.7.5</version>
   </dependency>
   <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-simple</artifactId>
       <version>1.6.4</version>
   </dependency>
Run Code Online (Sandbox Code Playgroud)

  • AFAIK你应该只有1个slf4j,即slf4j-log4j12或slf4j-simple,而不是两者. (21认同)
  • `slf4j-simple` 与 `slf4j-api` 的版本不同吗?它们可能会很好地协同工作,但我认为让它们使用相同的版本通常更安全和更好的做法。此外,如果您需要启用仅控制台日志记录,例如,在运行单元测试时,那么 `slf4j-simple` 似乎就足够了(不过对我来说是这样)。 (2认同)
  • 第二个依赖集对我有用。谢谢 (2认同)

ash*_*ish 41

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


Ben*_*uer 38

只需将其添加到您的pom.xml:

<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-simple</artifactId>
  <version>1.7.21</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

  • 解决方案对我有用; 值得指出文档(我发现错误解释的地方):http://www.slf4j.org/codes.html#StaticLoggerBinder (2认同)
  • 没有别的,但这对我来说在运行一个简单的kafka生产者示例时起作用.谢谢一堆! (2认同)
  • 似乎是特定于版本的。这也为我解决了这个问题。 (2认同)

Wol*_*ahl 29

这里有一些答案建议将slf4j-simple依赖项添加到你的maven pom文件中.您可能想要检查最新版本.

https://mvnrepository.com/artifact/org.slf4j/slf4j-simple, 您将找到最新版本的SLF4J Simple Binding.选择最适合你的那个(从2017年到2017年的1.7.25仍然是2018-02的稳定版本)并将其包含在你的pom.xml中.

Beta版2018年3月

<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-simple</artifactId>
  <version>2.0.0-alpha0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

稳定的版本

<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-simple</artifactId>
    <version>1.8.0-beta4</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

  • 为什么使用`<scope> test </ scope>`?根据我的经验,我至少需要`runtime`范围来确保`slf4j-simple`在类路径上.好奇你是如何只使用`test`范围... (5认同)

小智 25

我面临同样的错误.我在本地开发中配置了slf4j-api,slf4j-log4j12和log4j.所有配置都很好,但我从mvnrepository复制的slf4j-log4j12依赖项有测试范围<scope>test</scope>.当我删除它时,每件事都很好.

有时愚蠢的错误打破了我们的脑袋;)


Edw*_*ard 20

有时我们应该看到警告中的注释,例如.SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details..

您可以搜索此警告来的原因.
添加从罐子中的一个*slf4j-nop.jar,slf4j-simple.jar,slf4j-log4j12.jar,slf4j-jdk14.jarlogback-classic.jar*到类路径中应该解决的问题.

compile "org.slf4j:slf4j-api:1.6.1" compile "org.slf4j:slf4j-simple:1.6.1"

例如,将上面的代码添加到您build.gradlepom.xmlmaven项目的相应代码中.


sto*_*333 15

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

  • 或将依赖项添加到您的pom <dependency> <groupId> org.slf4j </ groupId> <artifactId> slf4j-log4j12 </ artifactId> </ dependency> (6认同)

sho*_*han 10

如果您正在使用maven进行依赖关系管理,那么您只需在pom.xml中添加以下依赖项即可

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>1.5.6</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

对于非Maven用户只需下载库并将其放入项目类路径中.

在这里您可以看到详细信息:http://www.mkyong.com/wicket/java-lang-classnotfoundexception-org-slf4j-impl-staticloggerbinder/

  • `这不是错误.此消息告诉您在类路径中没有添加任何记录器实现(例如Logback),因此NOP(无操作)log` [查找sarxos评论](https://github.com/sarxos/webcam-捕获/发布/ 278)@Paul提到需要添加logback-classic.另一种从`<artifactId> slf4j-api </ artifactId>`更改为`<artifactId> slf4j-simple </ artifactId>`的方法也可以完成.它在这里进行了说明(http://saltnlight5.blogspot.sg/2013/08/how-to-configure-slf4j-with-different.html) (2认同)

Anv*_*hat 9

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

  • 添加logback为我解决了这个问题。我将最新的logback classic放入pom(1.1.7),但失败了,因为slf4j依赖项太旧(1.6.2)。将logback降级到1.0.0并将slf4j保留在1.6.x上也可以工作,将slf4j升级到1.7.20并保留logback到1.1.7上也可以。 (2认同)

小智 7

当我收到以下错误时,我遇到了这个问题:

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.
Run Code Online (Sandbox Code Playgroud)

当我slf4j-api-1.7.5.jar在我的libs.

尽管我尝试了整个建议的补充 jars,例如slf4j-log4j12-1.7.5.jarslf4j-simple-1.7.5错误消息仍然存在。当我添加slf4j-jdk14-1.7.5.jar到java库时,问题终于解决了。

http://www.slf4j.org/download.html获取整个 slf4j 包


Cek*_*eki 5

在 Websphere 的情况下,您有旧版本的 slf4j-api.jar 1.4.x。或 1.5.x 位于某处。您在 tcServer 上观察到的行为(即故障转移到 NOP)发生在 slf4j 版本 1.6.0 及更高版本上。确保您在所有平台上使用 slf4j-api-1.6.x.jar,并且类路径上没有放置旧版本的 slf4j-api。


小智 5

Slf4j是底层日志框架的外观,如log4j,logback,java.util.logging.

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

  • log4j - slf4j-log4j12-1.7.21.jar
  • java.util.logging - slf4j-jdk14-1.7.21.jar等

如果错过了绑定jar,则抛出上述错误.您可以下载此jar并将其添加到classpath.

对于maven依赖,

<dependency> 
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-log4j12</artifactId>
  <version>1.7.21</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

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

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


gow*_*s23 5

请将以下依赖项添加到 pom 以解决此问题。

<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-simple</artifactId>
  <version>1.7.25</version>
  <scope>test</scope>
</dependency>

<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-api</artifactId>
  <version>1.7.25</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)


Kay*_*ayV 5

我在使用带有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>
Run Code Online (Sandbox Code Playgroud)


Vra*_*all 5

作为 jar 包含和纯 maven 解决方案的替代方案,您可以将它从 maven 中包含在 gradle 中。

版本示例 1.7.25

// https://mvnrepository.com/artifact/org.slf4j/slf4j-simple
api group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.25'
Run Code Online (Sandbox Code Playgroud)

将其放在build.gradle文件的依赖项中。


Aja*_*jay 5

     <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.7.21</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

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