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

右键单击项目-> Maven ->禁用Maven性质 右键单击项目-> Spring Tools > Update Maven Dependencies 右键单击项目->配置>转换Maven项目

其他回答

似乎删除。m2目录和:

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

在我的情况下,我有两个来源的依赖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

Gradle版;

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

如果这些日志是此修复的结果: 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中。