如何修复SLF4J:加载类"org.slf4j.impl.StaticLoggerBinder"."失败 [英] How do I fix "SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder"."

查看:59
本文介绍了如何修复SLF4J:加载类"org.slf4j.impl.StaticLoggerBinder"."失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,它有以下错误消息:

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.
在我尝试运行应用程序的任何脚本后出现此消息。我发现,正如它所说的那样,它不会创建日志,所以当出现故障时,我空手而归。

我在Amazon Linux2上运行它,它最接近CentOS和Redhat。

我找到了以下资源: 此问题在此处解决:http://www.slf4j.org/codes.html#StaticLoggerBinder 我可以从这里拿到我需要的罐子:https://repo1.maven.org/maven2/org/slf4j/slf4j-simple/1.6.2/slf4j-simple-1.6.2.jar 在获取这个JAR并将其放入我的应用程序的/lib之后,没有任何变化。

其他文章描述了将该文件添加到类路径。在Linux中,我得到的是:

# java -classpath /opt/opendj/lib/slf4j-simple-1.6.2.jar org.slf4j.impl.StaticLoggerBinder
Error: Could not find or load main class org.slf4j.impl.StaticLoggerBinder
# java -jar /opt/opendj/lib/slf4j-simple-1.6.2.jar org.slf4j.impl.StaticLoggerBinder
no main manifest attribute, in /opt/opendj/lib/slf4j-simple-1.6.2.jar

我是否正在尝试将其添加到类路径中?

如果需要,您可以通过执行以下操作重现此问题: 重现行为的步骤: 在CentOS或Amazon Linux2 EC2实例上安装更新版本的OpenDJ。安装Java 1.8.0 具体地说,Java-1.8.0-OpenJDK 在任何配置中安装服务器,然后运行状态脚本。

预期行为 应生成日志,并且不能显示任何警告消息。

推荐答案

首先,您应该看看这里:https://www.slf4j.org/codes.html

另外,您可以尝试将这些SLF4J Maven依赖项添加到您的POM中,并让我知道这是否有效:

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-api</artifactId>
    <version>2.13.3</version>
</dependency>
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>2.13.3</version>
</dependency>
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-slf4j-impl</artifactId>
    <version>2.13.3</version>
</dependency>

注意:考虑到maven依赖项版本正在更新,那么您可能更喜欢使用依赖项的最新版本(例如,log4j-api为2.17.0)

另一方面,这篇文章也可以帮助你: https://mkyong.com/java/log4j2-failed-to-load-class-org-slf4j-impl-staticloggerbinder/

这篇关于如何修复SLF4J:加载类&quot;org.slf4j.impl.StaticLoggerBinder&quot;.&quot;失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆