我得到如下错误。似乎有多个日志框架绑定到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.

当前回答

我在一个非maven项目中得到了这个问题,两个依赖的jar每个都包含一个slf4j。我解决了 通过删除一个依赖的jar,编译项目(当然会失败),然后将删除的jar添加回来。

其他回答

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

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

Sbt版:

添加排除(“org。Slf4j ", " Slf4j -log4j12")传递到包含Slf4j -log4j12的依赖项。例如,当使用Log4j 2.6使用Spark时:

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")
)

... org.codehaus.mojo cobertura-maven-plugin 2.7 测验 ch.qos.logback logback-classic 工具 com.sun ...

##我用这个来修复

... org.codehaus.mojo cobertura-maven-plugin 2.7 测验 ch.qos.logback logback-classic 工具 com.sun ...

Gradle版;

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

只使用所需的依赖项,而不是全部:)))。对于我来说,对于正常的日志记录过程,您需要这个依赖项来排除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>