9
votes

I'm opening this post after I couldn't find a solution in the post: Failed to load class "org.slf4j.impl.StaticLoggerBinder" error

I also opened a Maven project in IntelliJ and got the following error after choosing the option 'redeploy' in tomcat7 plugin:

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.

In the attached link, it was recommended to go to File-> Project Structure -> Artifacts and check for errors. This is what I see: enter image description here

I also have the following dependencies in pom.xml file:

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.5</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.5.6</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.7.21</version>
        </dependency>

Can you please help me finding the error?

4
please show what you see in "Project structure" when you click on "Libraries". Add it to your question.JimHawkins

4 Answers

14
votes

Maybe there are two issues:

  1. version mismatching of your dependencies
  2. an issue when you deploy your application

For reproducing your error I've created this mini program:

package de.so;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DemoSlf4j
{
    private static Logger logger = LoggerFactory.getLogger(DemoSlf4j.class);

    public static void main(String[] args)
    {
        logger.error("Start ...");
    }
}

with only these dependencies (same as you used) in pom.xml:

<dependencies>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.5</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.5.6</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.7.21</version>
    </dependency>
</dependencies>

I've got these messages:

SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/D:/Maven-Repo/org/slf4j/slf4j-log4j12/1.5.6/slf4j-log4j12-1.5.6.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/D:/Maven-Repo/org/slf4j/slf4j-simple/1.7.21/slf4j-simple-1.7.21.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory] SLF4J: The requested version 1.5.6 by your slf4j binding is not compatible with [1.6, 1.7] SLF4J: See http://www.slf4j.org/codes.html#version_mismatch for further details. log4j:WARN No appenders could be found for logger (de.so.DemoSlf4j). log4j:WARN Please initialize the log4j system properly.

When I use these dependencies, everything is fine. Look at the versions!

<dependencies>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.21</version> <!-- or use LATEST -->
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.7.21</version> <!-- or use LATEST -->
    </dependency>
</dependencies>

If you are using org.slf4j:slf4j-log4j12:1.7.21 instead of slf4j-simple (what is more likely for production purposes), you'll get:

log4j:WARN No appenders could be found for logger (de.so.DemoSlf4j). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

So do this:

  • look in your project dependencies if there are other artifacts which have cascading dependencies to logging frameworks (log4j, slf4f, ...).
  • check if your dependencies are proper deployed to your Tomcat. (.../WEB-INF/lib)
  • check the versions
1
votes

Maybe you get cracked jar in your project ,check it in debug model detail,I had this problem too, when I build with debug model, I see warning of:

/repository/ch/qos/logback/logback-classic/1.1.11/logback-classic-1.1.11.jar ,so remove it ,and build it again. problem resolved.

0
votes

You are providing a log api, and two different implementations, slf4j-log4j12 and slf4j-simple. I had the same issue, but in my case, it gave me an error message asking me to 'remove one' from class path.

You can try removing either slf4j-simple or slf4j-log4j12 from dependencies, clean and build project again.

0
votes

I met with the same issue. I fixed it by adding the following dependencies to my POM.xml file:

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>${slf4j.version}</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>${slf4j.version}</version>
    </dependency>

for the ${slf4j.version}, please assign the latest version number:

<properties>
    ...
    <slf4j.version>1.7.30</slf4j.version>
</properties>