Home > Software engineering >  Why would a "No SLF4J" provider found error occur when SLF4J is in Maven pom.xml file?
Why would a "No SLF4J" provider found error occur when SLF4J is in Maven pom.xml file?

Time:01-19

I am currently getting the below errors when trying to run a Spring Java program.

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.
SLF4J: Ignoring binding found at [jar:file:/C:/Users/user/.m2/repository/ch/qos/logback/logback-classic/1.2.11/logback-classic-1.2.11.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Ignoring binding found at [jar:file:/C:/Users/user/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.19.0/log4j-slf4j-impl-2.19.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See https://www.slf4j.org/codes.html#ignoredBindings for an explanation.

Here is the section in the pom.xml file that has the SLF4J and Log4J dependencies. This same section has worked in previous projects.

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

I don't have any components that are targeting indings for slf4j-api version 1..x or earlier. This error message seems to both say that I don't have SLF4J and that I have the wrong version.

If there are any thoughts on how to resolve this, I would appreciate it. Thank you!

I have tried using different dependencies in the pom.xml file, but ultimately these have worked in a previous program. I have also tried looking at dependencies that might also use SLF4J and excluding SLF4J from them, but I am still getting an error message. I have tried solutions from other similar questions asked but keep getting the same error.

CodePudding user response:

Based on this documentation:

Due to a break in compatibility in the SLF4J binding, as of release 2.19.0 two SLF4J to Log4j Adapters are provided.

  1. log4j-slf4j-impl should be used with SLF4J 1.7.x releases or older.
  2. log4j-slf4j2-impl should be used with SLF4J 2.0.x releases or newer.

Applications that take advantage of the Java Module System should use SLF4J 2.0.x and log4j-slf4j2-impl.

So the simplest way (if you need SLF4J 2) is to use <artifactId>log4j-slf4j2-impl</artifactId>. The other thing you can do is to revert back to slf4j-api 1.7.x.

Other notes:

  • The SLF4J log shows that logback-classic is also present in the dependency tree. You need to select either logback-classic or the log4j binding. Run mvn dependency:tree on your project to find where logback-classic is being added.

  • If you want to keep logback-classic, then same as mentioned above, you need to use the logback-classic compatible with SLF4J 2.

  • Related