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

当前回答

在我的情况下,我有两个来源的依赖log4 1在C:\Program Files\smcf.Ear目录和来自maven的第二个目录导致了sl4j的多重绑定。

删除smcf。耳朵目录为我解决了这个问题。

其他回答

对于那些寻找spring-boot类型依赖的解决方案的人来说,Gradle的魔法咒语是这样的:

configurations.all {
    exclude group: 'ch.qos.logback', module: 'logback-classic'
}

在你的构建中。Gradle在顶层(不是在依赖块内)。

在网上找到的所有其他解决方案(包括这里建议排除slf4j模块的解决方案)对我都不起作用。

这就是我的身材。gradle(片段):


// Removes the annoying warning about the multiple SLF4J implementations:
//    SLF4J: Class path contains multiple SLF4J bindings.
configurations.all {
    exclude group: 'ch.qos.logback', module: 'logback-classic'
}

dependencies {
    annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"

    implementation ('org.springframework.boot:spring-boot-starter-actuator')
    implementation ('org.springframework.boot:spring-boot-starter-data-mongodb-reactive')
    implementation ('org.springframework.boot:spring-boot-starter-webflux')

    annotationProcessor "org.projectlombok:lombok:${lombokVersion}"
    compileOnly "org.projectlombok:lombok:${lombokVersion}"

    // Removes the annoying warning:
    // warning: unknown enum constant When.MAYBE
    //  reason: class file for javax.annotation.meta.When not found
    // See: https://stackoverflow.com/questions/29805622/could-not-find-or-load-main-class-org-gradle-wrapper-gradlewrappermain/31622432
    implementation group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.2'

    // other stuff...

YMMV

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

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

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

... 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 ...

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

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