maven报错:SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder“. SLF4J: Defaulting to no-ope

2年前 (2022) 程序员胖胖胖虎阿
161 0 0

  今天在搭建maven项目时报错如下图:
maven报错:SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder“. SLF4J: Defaulting to no-ope

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.

  查看官网发现如下:
maven报错:SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder“. SLF4J: Defaulting to no-ope
  翻译过来大概就是如下:

SLF4J警告或错误消息及其含义 没有找到SLF4J提供程序。

当在类路径上找不到SLF4J提供程序时,就会报告此警告,即不是错误消息。在类路径上放置一个(且只有一个)slf4j-nop.jar
slf4j-simple.jar、slf4j-log4j12.jar、slf4j-jdk14.jar或logback-classic.jar应该可以解决这个问题。注意,这些提供程序必须针对slf4j-api
1.8或更高版本。

在没有提供程序的情况下,SLF4J将默认使用一个无操作(NOP)记录器提供程序。

请注意slf4j-api版本1.8。x,然后使用ServiceLoader机制。早期的版本依赖于静态绑定器机制,而slf4j-api不再支持这种机制。请阅读FAQ条目,SLF4J版本1.8.0有什么变化?进一步的重要细节。

如果您负责打包应用程序,而不关心日志记录,那么将slf4j-nop.jar放在应用程序的类路径上将消除此警告消息。请注意,诸如库或框架之类的嵌入式组件不应该声明对任何SLF4J提供者的依赖,而应该只依赖于SLF4J
-api。当一个库声明了一个在SLF4J提供程序上的编译时依赖时,它就把这个提供程序强加给了最终用户,从而否定了SLF4J的目的。

  意思是我们少了slf4j-nop.jar、slf4j-simple.jar、slf4j-log4j12.jar、slf4j-jdk14.jar或logback-classic.jar中的某些依赖,我们只要在项目中引入其中一个依赖就行了。我这里引入的是slf4j-simple.jar:

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

  接着clear一下maven,并且导入jar即可。

  如果导入依赖的时候有以下错误:
maven报错:SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder“. SLF4J: Defaulting to no-opeElement 'dependency' cannot have character [children], because the type's content type is element-only.

  翻译过来如下:

元素’dependency’不能具有字符[children],因为类型的内容类型是只包含元素的

  原因是依赖项不能包含空格,把多余空格给删了就行了。

maven报错:SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder“. SLF4J: Defaulting to no-ope

相关文章

暂无评论

暂无评论...