Search code examples
javatomcatgradledependenciesstatic-binding

Static Binding in Tomcat Multiple SLF4j Bindings


I have a gradle java project that I use Spring Boot to deploy. When I startup Spring-Boot with my jar file, I receive the following warning:

SLF4J: Class path contains multiple SLF4J bindings

SLF4J: Found binding in [apache-tomcat-8.0.23/lib/activemq-all-5.11.1jar!/org/slf4j/impl/StaticLoggerBinder.class

SLF4J: Found binding in [apache-tomcat-8.0.23/webapps/ProjectName/WEB-INF/lib/activemq-all-5.11.1jar!/org/slf4j/impl/StaticLoggerBinder.class

SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]

To remove this binding warning, I went into my gradle packager project that creates the jar file for Spring-Boot and did a dependencyInsight to trace the activemq-all jar and replace with the underlying jars explained here.

I found one instance of this activemq-all jar within my project:

:dependencyInsight
org.apache.activemq-all:5.9.1
/--- com.company.projectName:projectTitle:1.1.0
    /--- compile

I went into this project. Replaced the activemq-all dependency with the corresponding jars shown in the link above(so the slf4j-log4j12 was not included in the uber jar). Built the project again, updated my cache with the new jar that I created, and then reran the packager project that creates my war file. However, the activemq-all jar is still there. I can delete it locally from my cache, but on a gradle refresh it is replaced. Is there a special way to remove this transitive dependency from my project so I can resolve this binding issue, or is there something I am misunderstanding with removing a dependency from my project? I feel as if the dependencyInsight is not correctly mapping my dependencies for my activemq-all jar.

Please let me know if you need more information.


Solution

  • Solution: The activemq-all jar contains a log4j(version 1) binding with slf4j. This was causing my log4j2 configurations to be useless and log4j constantly complained because there was no longer a log4j configuration. I was chasing down log4j2 issues when it turned out to be a log4j1 configuration problem. In my project, I replaced the activemq-all jars with the solutions here and added all necessary bridges to bridge all of my logs to slf4j, and then had one(and only one!) binding with log4j2.