SLF4J: Class path contains multiple SLF4J bindings

2019-01-03 12:12发布

I'm getting the following error. It seems there are multiple logging frameworks bound to sl4j. 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.

标签: maven-2 slf4j
11条回答
走好不送
2楼-- · 2019-01-03 13:11

I just ignored/removed that jar file.

enter image description here

查看更多
再贱就再见
3楼-- · 2019-01-03 13:12

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> 
查看更多
smile是对你的礼貌
4楼-- · 2019-01-03 13:12

This issue took one whole day for me. Finally I decided to use not so good trick. Just put one of the below maven dependency in the very beginning of your pom.xml file. Use anyone of the file.slf4j-nop.jar, slf4j-simple.jar, slf4j-log4j12.jar, slf4j-jdk14.jar or logback-classic.jar , it should do the job. Note, use the latest jars from maven. Here's a link!. It is a good read. To understand you had to delete the slf4j jars created in local repository (in my case folder named ".m2") and run your project as Maven clean and Maven install and watch all the maven jars being downloaded. And you will figure out how JVM is picking the latest one (jar) for our program. To understand further,please remove the the POM dependency from the pom.xml file and again go to local repository and delete the all SLF4J jars and re-run the project as Maven clean and maven install , and makesure you watch for the downloads that are happening through maven, and then run your application to see the affect. You may notice that error or exception will not throw on placing or mentioning the dependency in the beginning this is because JVM is looking at the first come first jar in our project.But this is not good move. I would say use execlusion in the api's or jars where you find that particular api is downloading the slf4j jar. Something I noticed was, few jars (ex: hibernate annotations etc) are downloading slf4j when we build maven project. And that is the reason multiple slf4j jars getting injected in to our project.I hope this will help. This is just my experience.

查看更多
欢心
5楼-- · 2019-01-03 13:13
<!--<dependency>-->
     <!--<groupId>org.springframework.boot</groupId>-->
     <!--<artifactId>spring-boot-starter-log4j2</artifactId>-->
<!--</dependency>-->

I solved by delete this:spring-boot-starter-log4j2

查看更多
forever°为你锁心
6楼-- · 2019-01-03 13:13

Just use only required dependency, not all :))). For me, for normal work of logging process you need this dependency exclude others from pom.xml

<dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.5</version>
    </dependency>

    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>1.1.8</version>
    </dependency>

    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-core</artifactId>
        <version>1.1.8</version>
    </dependency>
查看更多
登录 后发表回答