Slf4j: 找到 slf4j-api 依赖但没有找到提供者

Slf4j: Found slf4j-api dependency but no providers were found

我使用龙目岛。 前段时间在构建项目时,编译器开始发出以下消息:

Found slf4j-api dependency but no providers were found. Did you mean to add slf4j-simple? See https://www.slf4j.org/codes.html#noProviders .

如果你关注link,有一个相当模糊的评论:

This warning, i.e. not an error, message is reported when no SLF4J providers 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. Note that these providers must target slf4j-api 1.8 or later.

In the absence of a provider, SLF4J will default to a no-operation (NOP) logger provider.

Please note that slf4j-api version 1.8.x and later use the ServiceLoader mechanism. Earlier versions relied on the static binder mechanism which is no longer honored by slf4j-api. Please read the FAQ entry What has changed in SLF4J version 1.8.0? for further important details.

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 providers but only depend on slf4j-api. When a library declares a compile-time dependency on a SLF4J provider, it imposes that provider on the end-user, thus negating SLF4J's purpose.

我不知道如何正确操作。如果你有经验,请告诉我怎么做。

tutorialspoint所述:

SLF4J stands for Simple Logging Facade for Java. It provides a simple abstraction of all the logging frameworks. It enables a user to work with any of the logging frameworks such as Log4j, Logback, JUL (java.util.logging), etc. using single dependency.

这意味着您必须在 SLF4J 本身的依赖项之上的类路径中提供具体的 java 日志记录库(Maven 示例):

<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>2.0.0-alpha0</version>
</dependency>

您还需要指定对首选日志记录库的依赖。例如:

对于标准jdk1.4日志记录

 <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-jdk14 -->
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-jdk14</artifactId>
    <version>2.0.0-alpha0</version>
    <scope>runtime</scope>
</dependency>  

对于slf4j-简单日志记录 :

<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-simple</artifactId>
    <version>2.0.0-alpha0</version>
    <scope>runtime</scope>
</dependency>

对于 log4j 日志记录 :

<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 -->
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>2.0.0-alpha0</version>
    <scope>runtime</scope>
</dependency>

参考此页面:http://www.slf4j.org/codes.html#noProviders

您可以添加以下任一依赖项:放置一个(且仅一个)slf4j-nop.jar slf4j-simple.jar、slf4j-log4j12.jar、slf4j-jdk14.jar 或 class 路径上的 logback-classic.jar 应该可以解决问题

我使用了来自 https://mvnrepository.com/artifact/org.slf4j/log4j-over-slf4j

的“slf4j-simple”maven 依赖项