Search code examples
javajakarta-eeslf4j

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)

Solution

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