SLF4J:类路径包含多个SLF4J绑定

use*_*140 194 maven-2 slf4j

我收到以下错误.似乎有多个日志框架绑定到sl4j.不知道如何解决这个问题.任何帮助是极大的赞赏.

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.
Run Code Online (Sandbox Code Playgroud)

use*_*140 118

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

<exclusions>
    <exclusion>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
    </exclusion>
</exclusions> 
Run Code Online (Sandbox Code Playgroud)

  • 找出log4j如何在你的路径上运行mvn依赖:树和梳理,然后将上面的代码段添加到你的pom.xml中的那个依赖项 (20认同)
  • 在这种情况下哪个依赖性引起冲突,我有依赖树有3个提到的slf4j (9认同)

Ker*_*rem 53

Gradle版;

configurations.all {
    exclude module: 'slf4j-log4j12'
}
Run Code Online (Sandbox Code Playgroud)

  • 将模型从主应用程序导入到自动化框架中。这解决了我的gradle问题。ty。 (2认同)
  • 否:ant 不是一个依赖性感知工具。强烈考虑将您的构建移植到 gradle。 (2认同)
  • 优秀。从几个小时的依赖地狱中拯救了我! (2认同)

Tii*_*ina 18

该错误可能会提供更多这样的信息(尽管您的jar名称可能不同)

SLF4J:在[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:在[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]

注意到冲突来自两个罐子,名为logback-classic-1.2.3log4j-slf4j-impl-2.8.2.jar.

运行mvn dependency:tree该项目的pom.xml父文件夹,赠送:

依赖树冲突

现在选择你想要忽略的那个(可以消耗一个微妙的努力,我需要更多的帮助)

我决定不使用从spring-boot-starter-data-jpa(顶部依赖)导入的那个spring-boot-starter,通过spring-boot-starter-logging,pom变成:

    <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>
Run Code Online (Sandbox Code Playgroud)

在上面的pom spring-boot-starter-data-jpa中将使用spring-boot-starter配置在同一个文件中,该文件排除logging(包含logback)

  • 感谢您介绍 `mvn dependency:tree`。这太有帮助了... (7认同)

Ruu*_*uud 9

Sbt版本:

附加exclude("org.slf4j", "slf4j-log4j12")到可传递包含的依赖项slf4j-log4j12.例如,将Spark与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")
)
Run Code Online (Sandbox Code Playgroud)

  • 简单构建工具* (3认同)

Naf*_*ema 9

1.找到冲突的jar

如果无法从警告中识别依赖项,则可以使用以下命令来识别冲突的 jar

mvn dependency: tree
Run Code Online (Sandbox Code Playgroud)

这将显示项目的依赖关系树以及已拉入与slf4j-log4j12JAR 的另一个绑定的依赖关系。

  1. 解决

现在我们知道了有问题的依赖项,我们需要做的就是slf4j-log4j12从该依赖项中排除 JAR。

例如 - 如果spring-security依赖项还引入了与slf4j-log4j12JAR 的另一个绑定,那么我们需要slf4j-log4j12spring-security依赖项中排除该 JAR。

 <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>
Run Code Online (Sandbox Code Playgroud)

注意 -在某些情况下,多个依赖项已与 JAR 绑定slf4j-log4j12,您无需为每个已引入的依赖项添加排除项。您只需添加排除依赖项,该依赖项已放置在第一的。

前任 -

<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>
Run Code Online (Sandbox Code Playgroud)

如果您使用 gradle,则将以下代码添加到您的build.gradle文件中以从所有模块中排除 SLF4J 绑定

configurations.all {
    exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
}
Run Code Online (Sandbox Code Playgroud)


VK_*_*217 5

我只是忽略/删除了那个 jar 文件。

在此输入图像描述


Gan*_*ank 5

<!--<dependency>-->
     <!--<groupId>org.springframework.boot</groupId>-->
     <!--<artifactId>spring-boot-starter-log4j2</artifactId>-->
<!--</dependency>-->
Run Code Online (Sandbox Code Playgroud)

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