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

当前回答

Gradle版;

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

其他回答

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

似乎删除。m2目录和:

mvn install -DskipTests -T 4为我解决了这个问题。

如果这些日志是此修复的结果: https://stackoverflow.com/a/9919375/2894819

当你的某个库实际使用它时。而且您的应用程序不需要SL4J,只需将实现替换为runtimeOnly即可。

// contains dependency to sl4j-api
implementation("com.github.doyaaaaaken:kotlin-csv-jvm:1.2.0")

// add this to remove both warnings
runtimeOnly("org.slf4j:slf4j-nop:1.7.36")

在这种情况下,当你运行你的应用程序时,实际的依赖关系将被库包含一次,而不会被包含到你的application.jar本身的bundle中。

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

SLF4J:在中找到绑定 [jar文件:/ D: / Java /仓库/ ch / qos / logback / logback-classic / 1.2.3 / logback-classic-1.2.3.jar ! / org/slf4j/impl/StaticLoggerBinder.class] SLF4J:在中找到绑定 [jar文件:/ D: / Java /仓库/ 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.3和log4j-slf4j-impl-2.8.2.jar的jar。

在这个项目的pom.xml父文件夹中运行mvn dependency:tree,给出:

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

我决定不使用通过spring-boot-starter和spring-boot-starter-logging从spring-boot-starter-data-jpa(顶级依赖项)导入的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>

在上述pom中,spring-boot-starter-data-jpa将使用在同一文件中配置的spring-boot-starter,其中不包括日志记录(它包含logback)

对我来说,从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" />

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