Found slf4j-api dependency but no providers were found
Asked Answered
M

8

47

I use Lombok. Some time ago when building a project, the compiler started issuing the following message:

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

If you follow the link, there is a rather vague comment:

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.

I have no idea how to do it correctly. If you have an experience, please, explain me how to do it.

Maiden answered 12/2, 2019 at 14:54 Comment(1)
Have you got one of slf4j-nop.jar slf4j-simple.jar, slf4j-log4j12.jar, slf4j-jdk14.jar or logback-classic.jar on the class path ?Zubkoff
L
61

As stated in 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.

This means that you have to provide a concrete java logging library on your classpath on top of the dependency for SLF4J itself (Example with 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>

You will also need to specify the dependency on your preferred logging library. For instance:

For standard jdk1.4 logging :

 <!-- 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>  

For slf4j-simple logging :

<!-- 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>

For log4j logging :

<!-- 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>
Lenzi answered 29/9, 2019 at 3:27 Comment(3)
works for me with slf4j-simple and 2.0.7Dich
I'm not sure what I was doing wrong, but these didn't completely work for me. Doing some troubleshooting, I removed the slf4j jar entirely and ran my code, which produced a class-not-found exception, specifying 'org/slf4j/LoggerFactory' as the missing class. I then replaced the no op jar and the api jar back in my pom file as well as assigned the slf4j.loggerfactory property. java System.setProperty("org.slf4j.LoggerFactory","org.apache.logging.log4j.simple.SimpleLoggerContextFactory"); This proved successful in removing the error.Hasseman
I'm using this gradle plugin de.qualersoft.jmeter and getting these same slf4j messages. I added the slf4j-simple dependency but it didn't do a thing...Mansized
S
5

Refer this Page: http://www.slf4j.org/codes.html#noProviders

You may add either of the following dependencies: 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

I used "slf4j-simple" maven dependency from https://mvnrepository.com/artifact/org.slf4j/log4j-over-slf4j

Syck answered 29/9, 2021 at 13:24 Comment(1)
I download slf4j-simple.jar and add to project libraries and solve problem, ThanksInsurable
J
4

To disable this message from a library that depends on slf4j, you can add slf4j-nop to your dependencies before your library, e.g.

implementation 'org.slf4j:slf4j-nop:2.0.7'

At the time of writing, the latest version of slf4j is 2.0.7, this can be checked at https://central.sonatype.com/artifact/org.slf4j/slf4j-nop

If you need output from the library you are using, you can add slf4j-simple instead of slf4j-nop

Jaddan answered 7/8, 2023 at 7:2 Comment(2)
Hi.. I am using Spring boot 3.0.5 with Lombok in maven. No matter what version/artifact of this slf4j I add. I am not getting rid of SLF4J: No SLF4J providers were found. SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details. SLF4J: Class path contains SLF4J bindings targeting slf4j-api versions 1.7.x or earlier. AS A RESULT NOT ABLE TO GENERATE JAR FILE USING RUN AS>MAVEN INSTALL.Preclinical
@JPG, there is no such message for me when I generate Spring Boot project with Lombok and run it with ./mvnw spring-boot:run. Here is my URL to generate projectJaddan
B
3

This can be due to the version of slf4J API and you are using. try this changing the version like this.

<dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.25</version>
    </dependency>
Brassie answered 31/1, 2023 at 13:8 Comment(0)
D
1

You can refer to THIS

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 the many available providers such as slf4j-nop.jar slf4j-simple.jar, slf4j-reload4j.jar, slf4j-jdk14.jar or logback-classic.jar on the class path should solve the problem.

Daliladalis answered 8/7, 2023 at 1:41 Comment(0)
A
1

In my case, I'm making use of maven. All I have to do is select the 'reload all maven my projects' option from the maven menu.. This helps with full project import which include: read all config files and getting maven project model, resolve all dependencies, resolve all plugins.

Because Slf4j is an abstract class, it immediately resolves the Slf4j provider issue by supplying the necessary implementation for the slf4j (Simple Login Facade for Java) class.

Andresandresen answered 11/12, 2023 at 14:2 Comment(0)
D
0

In my case, this error was triggered from adding a new dependency: com.amazonaws:DynamoDBLocal:2.0.0+

The problem was fixed by adding exclude(group = "org.eclipse.jetty"). As in:

testImplementation("com.amazonaws:DynamoDBLocal:2.0.0+") {
   exclude(group = "org.eclipse.jetty")
} 

Duluth answered 27/11, 2023 at 11:58 Comment(0)
M
0

In my case, I added a new library (flying-saucer-pdf) to the project and the app can't start. The issue was that this new library has a dependency with an existing library (slf4j-api) in the project (a collision). This is called "transitive dependency".

If you use gradle, in your build.gradle file you need to exclude that transitive dependency (because you already have the required library).

implementation('org.xhtmlrenderer:flying-saucer-pdf:9.5.1') {
    exclude group: 'org.slf4j', module: 'slf4j-api'
}
Mabuse answered 26/6 at 16:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.