Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SLF4J: slf4j-api 1.6.x (or later) is incompatible with this binding

2015-09-28 10:02:21,890 ERROR [STDERR] (HDScanner) SLF4J: slf4j-api 1.6.x (or later) is incompatible with this binding.
2015-09-28 10:02:21,891 ERROR [STDERR] (HDScanner) SLF4J: Your binding is version 1.5.5 or earlier.
2015-09-28 10:02:21,891 ERROR [STDERR] (HDScanner) SLF4J: Upgrade your binding to version 1.6.x.
2015-09-28 10:02:21,891 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/metasolv-web]] (HDScanner) Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.NoSuchMethodError: org.slf4j.impl.StaticLoggerBinder.getSingleton()Lorg/slf4j/impl/StaticLoggerBinder;

How do I fix this error? Also, in my application, I do not use slf4j anywhere, only the Dozer library uses it. from the below stacktrace I see that the spring application is using the slf4j, but why does it not load one on its own?

java.lang.NoSuchMethodError: org.slf4j.impl.StaticLoggerBinder.getSingleton()Lorg/slf4j/impl/StaticLoggerBinder;
    at org.slf4j.LoggerFactory.bind(LoggerFactory.java:128)
    at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:107)
    at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:295)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:269)
    at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:156)
    at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:132)
    at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:645)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:191)
like image 402
Zeus Avatar asked Sep 28 '15 15:09

Zeus


People also ask

What is SLF4J binding?

Bindings are basically implementations of a particular SLF4J class meant to be extended to plug in a specific logging framework. By design, SLF4J will only bind with one logging framework at a time. Consequently, if more than one binding is present on the classpath, it will emit a warning.

How do I know if SLF4J is binding?

Put a breakpoint on .. say.. LOG.info(...). Once debugger stops there, step into.. and viola.. you will find yourself in the code of the actual logger... say log4j or logback..

Is SLF4J compatible with Log4j2?

It allows applications coded to the SLF4J API to use Log4j2 as the implementation.

How do I know what version of SLF4J I have?

To see which version of slf4j-api is pulled in by Maven, use the maven dependency plugin as follows. In your pom. xml file, explicitly declaring a dependency on slf4j-api matching the version of the declared provider/binding will make the problem go away.


1 Answers

I had to excluded the slf4j depenedencies from the dozer library and add dependencies directly to the POM file.

As mentioned by @Powerlord, i had to add two libraries, one for the core slf4j and the other one is a binding library.

Maven dependencies below.

       <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.6.6</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.6.6</version>
        </dependency>

        <dependency>
            <groupId>net.sf.dozer</groupId>
            <artifactId>dozer</artifactId>
            <version>5.5.1</version>
            <exclusions>
                <exclusion>
                    <artifactId>jcl-over-slf4j</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>slf4j-api</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>
like image 190
Zeus Avatar answered Sep 19 '22 10:09

Zeus