[Solved] SLF4J: Class Path Contains Multiple SLF4J Bindings.

In this post,we will see about SLF4J: Class Path Contains Multiple SLF4J Bindings.

Using maven

If you are looking for quick solution for this issue, you need to find out how log4j is present on your path.
run mvn dependency:tree and figure out the maven dependency and exclude log4j with snippet below to that dependency in your pom.xml.

This should resolve SLF4J: Class Path Contains Multiple SLF4J Bindings.

Using gradle

If you are using gradle, you need to use following code to exclude following dependency.

I have provided example below to figure out the dependency from which you should exclude log4j dependency.

Understand the warning

Let’s first understand the warning.

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/apple/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/Users/apple/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.13.1/log4j-slf4j-impl-2.13.1.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]

It simply says ClassPath contains multiple SLF4J bindings i.e logback-classic-1.2.3.jar and log4j-slf4j-impl-2.13.1.jar.

To understand the warning, we need to understand about SLF4J.

The Simple Logging Facade for Java (SLF4J) provides simple abstraction or facade for various logging frameworks such as log4j, logback, and java.util.logging etc. and it allows the end-user to plug-in the desired logging framework at deployment time.

SLF4J looks for bindings on the classpath to plugin logging framework. If more than one binding is present on the classpath, it will give a warning.

Please note that this is just a warning, not an error, it will pick one of the binding and will go ahead with it.

For example:
SLF4J has chosen logback in above warning. You can have a look at this line.

SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]

How to resolve SLF4J: Class-Path Contains Multiple SLF4J Bindings?

We need to find a conflicting jars to find root cause of the warning.

You can use the following command to trace the conflicting jar.

[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:2.2.2.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-starter:jar:2.2.2.RELEASE:compile
[INFO] | | +- org.springframework.boot:spring-boot-starter-logging:jar:2.2.2.RELEASE:compile
[INFO] | | | +- ch.qos.logback:logback-classic:jar:1.2.3:compile
[INFO] \- org.apache.logging.log4j:log4j-slf4j-impl:jar:2.13.1:compile

As you can see, we have two slf4j bindings here.

  • ch.qos.logback:logback-classic:jar
  • org.apache.logging.log4j:log4j-slf4j-impl:jar

logback-classic is transitive dependency, fetched due to spring-boot-starter-web. We have added explicitly log4j-slf4j-impl to use log4j in our project.

To avoid this warning, we need to exclude the unwanted dependencies in pom.xml.
In this example, I have excluded logback-classic.

Update the maven project and run the application. You should not get SLF4J Warning: Class Path Contains Multiple SLF4J Bindings now.

Reference

SLF4J: class path contains multiple SLF4J bindings.

That’s all about SLF4J: Class Path Contains Multiple SLF4J Bindings.

Was this post helpful?

Related Posts

  • SLF4J: Failed to Load Class org.slf4j.impl.StaticLoggerBinder
    05 April

    SLF4J: Failed to Load Class org.slf4j.impl.StaticLoggerBinder

    Table of ContentsSLF4J LibraryComponents That Are Needed to Implement the SLF4J FunctionalitiesNotes for Different VersionsExample of SLF4J: Failed to Load Class org.slf4j.impl.StaticLoggerBinderResolving the ErrorConclusionWas this post helpful? This article discusses the SLF4J library and the common error SLF4J: Failed to load class org.dlf4j.impl.StaticLoggerBinder that shows up while trying to use the library functionalities. SLF4J Library […]

  • 23 August

    log4j properties file example

    Logging is essential part of programming. It helps developer to track code workflow and fix bugs efficiently. If we get any issue in the code, we check logs for that workflow or functionality. Log4j is fast , reliable logging framework and can be easily integrated with the code. It is possible to enable logging at […]

  • 23 May

    log4j xml configuration example

    Logging is essential part of programming. It helps developer to track code workflow and fix bugs efficiently. If we get any issue in the code, we check logs for that workflow or functionality. Log4j is fast , reliable logging framework and can be easily integrated with the code. It is possible to enable logging at […]

Leave a Reply

Your email address will not be published.

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.