Do multiple SLF4J bindings cause an error?

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

SLF4J: the class path contains several 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 / osusch / 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/exist/StaticLoggerBinder.class] SLF4J: see http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: slf4j-api 1.6.x (or later) is not compatible with this binding. SLF4J: Your binding is version 1.5.5 or earlier. SLF4J: Update your binding to version 1.6.x. or 2.0.x An exception in the "main" thread java.lang.NoSuchMethodError: org.slf4j.impl.StaticLoggerBinder.getSingleton () Lorg / slf4j / impl / StaticLoggerBinder;

and this is the corresponding part 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 someone please tell me how to solve this problem?

+11
java maven dependencies slf4j
source share
6 answers

There are several solutions:

  • Make sure that it contains only one slf4j jar (possibly with a higher version) if you have a couple of them with different versions on the way to your class.
  • Sometimes it is not possible to exclude several cans of slf4j because they can be used by other cans inside that are on your way to the class. These dependent jars may belong to different versions of slf4j jars, which will cause your application to crash. In such cases, make sure you have a jar with a higher version of SLF4j added in front of another jar using SLF4J cans . This ensures that your java program picks up the latest version of SLF4J, which obviously has backward compatibility.
+23
source share

If your project has a dependency on another project and the other uses slf4j, as well as with a different version, try using excusion

 <exclusions> <exclusion> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> </exclusion> </exclusions> 
+3
source share

I would suggest using the following dependency in maven,

 <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> 

This solved my problem, although I have more dependencies with slf4j.

+1
source share

This happens when there is more than one can. To check if there is already a jar or not, go to the project → java resources → maven dependencies and check if the bank exists there or not. If it is available and you still get an error. Then find the location of this jar file in the .m2 \ resources folder and delete the full folder associated with this jar file, then download the new version and import it into your project. :)

Someday I get errors even if I downloaded the right jar file with the correct version in my pom.xml file. Then I need to remove it from my pom.xml and download this jar from google and import it into my project. Make sure that if you do this, do not forget to go to the project properties → Assembly Installation tab → Click Add → Java Build Path Entries and click on this jar file and click Apply.

0
source share

When multiple bindings are available on the class path, select the one and only one binding you want to use, and delete the other bindings.

Try removing the explicitly added dependency 'org.slf4j' or 'log4j2'.

0
source share

The answer from Fateh is correct, I had to spend some time to figure out how to use it, so I add a complete solution:

  1. Run mvn dependency:tree

  2. find out which library uses slf4j:

     [INFO] +- net.lightbody.bmp:browsermob-proxy:jar:2.0-beta-8:compile [INFO] | +- org.slf4j:slf4j-jdk14:jar:1.7.25:compile 
  3. exclude it from Maven like this:

      <dependency> <groupId>net.lightbody.bmp</groupId> <artifactId>browsermob-proxy</artifactId> <version>2.0.0</version> <exclusions> <exclusion> <groupId>org.slf4j</groupId> <artifactId>slf4j-jdk14</artifactId> </exclusion> </exclusions> </dependency> 
0
source share

All Articles