我收到以下错误.似乎有多个日志框架绑定到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)
Ker*_*rem 53
Gradle版;
configurations.all {
exclude module: 'slf4j-log4j12'
}
Run Code Online (Sandbox Code Playgroud)
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.3和log4j-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)
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)
1.找到冲突的jar
如果无法从警告中识别依赖项,则可以使用以下命令来识别冲突的 jar
mvn dependency: tree
Run Code Online (Sandbox Code Playgroud)
这将显示项目的依赖关系树以及已拉入与slf4j-log4j12JAR 的另一个绑定的依赖关系。
现在我们知道了有问题的依赖项,我们需要做的就是slf4j-log4j12从该依赖项中排除 JAR。
例如 - 如果spring-security依赖项还引入了与slf4j-log4j12JAR 的另一个绑定,那么我们需要slf4j-log4j12从spring-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)
<!--<dependency>-->
<!--<groupId>org.springframework.boot</groupId>-->
<!--<artifactId>spring-boot-starter-log4j2</artifactId>-->
<!--</dependency>-->
Run Code Online (Sandbox Code Playgroud)
我通过删除这个解决了:spring-boot-starter-log4j2
| 归档时间: |
|
| 查看次数: |
278459 次 |
| 最近记录: |