我得到如下错误。似乎有多个日志框架绑定到slf4j。不知道如何解决这个问题。任何帮助都非常感激。

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.

当前回答

<!--<dependency>-->
     <!--<groupId>org.springframework.boot</groupId>-->
     <!--<artifactId>spring-boot-starter-log4j2</artifactId>-->
<!--</dependency>-->

我通过删除这个来解决:spring-boot-starter-log4j2

其他回答

<scope>提供</scope>和< exclsions >的组合不适合我。

我不得不使用这个:

<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <scope>system</scope>
    <systemPath>${project.basedir}/empty.jar</systemPath>
</dependency>

其中empty.jar是一个没有任何内容的jar文件。

Gradle版;

configurations.all {
    exclude module: 'slf4j-log4j12'
}

我通过Intellij项目中的Project Structure解决了这个问题。 我删除了名为:Maven: org.apache.logging.log4j:log4j-to-slf4j-impl:2.14.1的文件

这个文件没有显示在这张图片中。您可能会看到两个库被称为log4j-to-slf4j。删除一个就可以了。

通过在(pom.xml的)依赖项中添加以下导致冲突的排除来解决。

<exclusions>
    <exclusion>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
    </exclusion>
</exclusions> 

对我来说,从log4j切换到logback后,这变成了一个Eclipse/Maven问题。查看一下.classpath文件并搜索字符串“log4j”。

在我的情况下,我有以下: <classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-log4j12/1.7.1/slf4j-log4j12-1.7.1.jar"/> <classpathentry kind="var" path="M2_REPO/log4j/log4j/1.2.17/log4j-1.2.17.jar" />

从文件中删除这些条目(或者您可以重新生成它)可以解决这个问题。