SLF4J: Class path contains multiple SLF4J bindings
Solution 1
Resolved by adding the following exclusion in the dependencies (of pom.xml) that caused conflict.
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
Solution 2
Gradle version;
configurations.all {
exclude module: 'slf4j-log4j12'
}
Solution 3
The error probably gives more information like this (although your jar names could be different)
SLF4J: Found binding in [jar:file:/D:/Java/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:/D:/Java/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.8.2/log4j-slf4j-impl-2.8.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
Noticed that the conflict comes from two jars, named logback-classic-1.2.3
and log4j-slf4j-impl-2.8.2.jar
.
Run mvn dependency:tree
in this project pom.xml parent folder, giving:
Now choose the one you want to ignore (could consume a delicate endeavor I need more help on this)
I decided not to use the one imported from spring-boot-starter-data-jpa
(the top dependency) through spring-boot-starter
and through spring-boot-starter-logging
, pom becomes:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
in above pom spring-boot-starter-data-jpa
would use the spring-boot-starter
configured in the same file, which excludes logging
(it contains logback
)
Solution 4
Sbt version:
Append exclude("org.slf4j", "slf4j-log4j12")
to the dependency that transitively includes slf4j-log4j12
. For example, when using Spark with Log4j 2.6:
libraryDependencies ++= Seq(
// One SLF4J implementation (log4j-slf4j-impl) is here:
"org.apache.logging.log4j" % "log4j-api" % "2.6.1",
"org.apache.logging.log4j" % "log4j-core" % "2.6.1",
"org.apache.logging.log4j" % "log4j-slf4j-impl" % "2.6.1",
// The other implementation (slf4j-log4j12) would be transitively
// included by Spark. Prevent that with exclude().
"org.apache.spark" %% "spark-core" % "1.5.1" exclude("org.slf4j", "slf4j-log4j12")
)
Solution 5
1.Finding the conflicting jar
If it's not possible to identify the dependency from the warning, then you can use the following command to identify the conflicting jar
mvn dependency: tree
This will display the dependency tree for the project and dependencies who have pulled in another binding with the slf4j-log4j12
JAR.
- Resolution
Now that we know the offending dependency, all that we need to do is exclude the slf4j-log4j12
JAR from that dependency.
Ex - if spring-security
dependency has also pulled in another binding with the slf4j-log4j12
JAR, Then we need to exclude the slf4j-log4j12
JAR from the spring-security
dependency.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
Note - In some cases multiple dependencies have pulled in binding with the slf4j-log4j12
JAR and you don't need to add exclude for each and every dependency that has pulled in.
You just have to do that add exclude dependency with the dependency which has been placed at first.
Ex -
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
</dependencies>
If you work with gradle then add following code to your build.gradle
file to exclude SLF4J binding from all the modules
configurations.all {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
}
Related videos on Youtube
user1493140
Updated on July 08, 2022Comments
-
user1493140 almost 2 years
I'm getting the following error. It seems there are multiple logging frameworks bound to slf4j. Not sure how to resolve this. Any help is greatly appreciated.
SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/C:/Users/admin/.m2/repository/org/slf4j/slf4j-log4j12/1.6.4/slf4j-log4j12-1.6.4.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/C:/Users/admin/.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.
-
user1493140 over 11 yearsResolved Using
<exclusions> <exclusion> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> </exclusion> </exclusions>
in the dependecies (of pom.xml) that caused conflict helped resolve the problem -
michael about 11 yearsduplicate: stackoverflow.com/questions/8921382/…
-
Peter Keller about 10 yearsDid you already check slf4j.org/codes.html#multiple_bindings as stated in the warning?
-
Roberto about 10 yearsMaybe It could be better to add an answer (auto-answer) to this question and mark it as "Accepted", So the question will appear as "Solved" in the SO searchs
-
user1493140 about 10 yearsRoberto, Thanks for feedback. I copied the solution from the comment and posted it as answer.
-
Amit Sinha almost 5 yearsI am getting the same error but in Pom.xml file we don't have slf4j dependency.
-
granadaCoder almost 5 yearsFor future readers, here is a good article for log4j2 (<<emphasis on the "2" here) logicbig.com/tutorials/spring-framework/spring-boot/log4j2.html the key phrase in the article is : "spring-boot-starter-log4j2 is a starter for using Log4j2. It is an alternative to spring-boot-starter-logging."
-
Master Mind over 2 yearsAdd exclude dependency with the dependency which has been placed at first.
-
-
PUG over 9 yearswhich dependancy caused conflict in this case, I have dependancy tree there are 3 mentions of slf4j
-
Will about 9 yearsImporting Models from the main application into automation framework.. this resolved my problem with gradle. ty.
-
Balaji Boggaram Ramanarayan almost 9 yearsIs there any ant version of doing this ?
-
cyber-monk over 8 yearsto find out how log4j is getting on your path run mvn dependency:tree and comb through, then add the snippet above to that dependency in your pom.xml
-
Matthew Mark Miller about 8 yearsno: ant is not a dependency aware tool. Strongly consider porting your build to gradle.
-
ioleo almost 7 yearsstrongly recomend porting your build to sbt :)
-
Ashok kumar Ganesan over 6 years@user1493140 Still it is not working for me. <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> <exclusions> <exclusion> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> </exclusion> </exclusions> </dependency>
-
Petrus Theron about 6 yearsWhat does Sbt stand for?
-
PlunkettBoy about 6 yearsExcellent. Saved me from a few hours of dependency hell!
-
Benny almost 6 yearsSimple Build Tool*
-
Jan Lochman over 5 yearsThank you for introducing
mvn dependency:tree
. It's so much helpful... -
ihebiheb about 5 yearsfor me another jar war the cause. I had to exclude the artifacts with id slf4j-nop and slf4j-jdk14. The dependency that caused the conflict for me was clover-maven-plugin
-
Lei Yang over 4 yearsnot clear: do you mean delete/comment above xml section, or add?
-
Lei Yang over 4 yearsis the version (
slf4j-log4j12
) applicable for all? or should we find out the version from mvn dependency:tree? -
Jhon Hernández almost 3 yearsAfter number 1, the other options doesn´t appera anymore...thanks more things to fix
-
Partha Paul over 2 yearsHow to do in Maven?
-
Kerem over 2 years@ParthaPaul the previous answer is the one for that. stackoverflow.com/a/22638585/1505341