Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple SLF4J bindings cause error?

Tags:

I have a problem with my dependency tree and multiple SLF4J binding. What I found out so far is that usually this only causes a warning but in my case it seems to prevent my program from running: These are the exceptions I get:

SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/C:/Users/FischerNi/.m2/repository/org/slf4j/slf4j-jdk14/1.5.3/slf4j-jdk14-1.5.3.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/C:/Users/FischerNi/.m2/repository/org/slf4j/slf4j-log4j12/1.6.1/slf4j-log4j12-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: slf4j-api 1.6.x (or later) is incompatible with this binding. SLF4J: Your binding is version 1.5.5 or earlier. SLF4J: Upgrade your binding to version 1.6.x. or 2.0.x Exception in thread "main" java.lang.NoSuchMethodError: org.slf4j.impl.StaticLoggerBinder.getSingleton()Lorg/slf4j/impl/StaticLoggerBinder;

and this is the relevant piece of my dependencies: net.lightbody.bmp browsermob-proxy 2.0-beta-8

    <!-- LOGGING DEPENDENCIES - LOG4J -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
    </dependency>

Can somebody please tell me how to resolve this issue?

like image 529
Biffy Avatar asked Oct 29 '13 11:10

Biffy


People also ask

What is SLF4J error?

impl. StaticLoggerBinder". This is a warning which is caused when there are no SLF4J bindings provided in the classpath. SLF4J: Failed to load class "org.

What are SLF4J bindings?

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.

What is SLF4J jdk14?

slf4j is Simple Logging Facade for Java .


1 Answers

There are couple of solutions to this:

  • Make sure that you include only one slf4j jar(probably with the higher version) if you have couple of them with different versions on your class path.
  • Sometimes it may not be possible to exclude multiple slf4j jars, as they may be used by other jars internally, which are on your class path. These dependent jar may refer to different versions of slf4j jars which causes your application to fail. In such cases, make sure that you have the jar with higher version of SLF4j added before other jar using SLF4J jars. This will make sure that your java program will pick up the latest version of the SLF4J which obviously is backward compatible.
like image 183
Ankur Shanbhag Avatar answered Mar 13 '23 14:03

Ankur Shanbhag