我得到如下错误。似乎有多个日志框架绑定到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.
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")
)
对于那些寻找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
错误可能会提供更多类似这样的信息(尽管您的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)