Class Path Contains Multiple Slf4j Bindings



SLF4J: Class path contains multiple SLF4J bindings error occurs in many projects, especially those having multiple dependencies. Here we the reason and how to deal with it!

Contains

Erroneous project configuration

Class Path Contains Multiple Slf4j Bindings Gradle

SLF4J is having 2 depedencies in classpath. One is slf4j-log4j12 and another is logback. The Logback is added in class path by apache lens projec used in lens module. I have added exclusion to remove that in this PR PR type Bug Fix JIRA ZEPPELIN-1410 SLF4J: Class path contains multiple SLF4J bindings Fix This removes logback in the package of zeppelin. That’s all about SLF4J Warning: Class Path Contains Multiple SLF4J Bindings. Classpath contains multiple SLF4J bindings. You should have only one binding in the classpath. If you have more than one binding, you will get a warning listing the bindings and the locations of them. For suppose, if we have the bindings slf4j-jdk14.jar and slf4j-nop.jar in the classpath.

Here is sample Maven project configuration that brings more than one SLF4J binding into the classpath:

Sample Java code that writes to logs:

Class

This simple code will allow us to see the error:

The above code produces the following output:

Binding SLF4J to only one logging framework

Remember that SLF4J is only a facade to logging frameworks – slf4j-api. It finds wrappers for all available logging frameworks on the runtime classpath and tries to load them. The error tells us that it found more than one logging framework and don’t know which one is correct.

Slf4j

To fix the error we have choose only one logging framework that should be used by SLF4J at runtime. In case of simple duplication in Maven POM you just need to remove redundant logging framework bindings – slf4j-log4j12 or slf4j-simple in our case.

Usually the culprit is not that obvious and is hidden in transitive dependencies. To find all SLF4J bindings you can list effective POM.

Class Path Contains Multiple Slf4j Bindings. Spring Boot

Leaving only one of the bindings makes the SLF4J to work as expected:

Class Path Contains Multiple Slf4j Bindings Spark

References: