我收到以下错误。似乎有多个日志框架绑定到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.
通过在导致冲突的依赖项(pom.xml)中添加以下排除项来解决此问题。
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
对我来说,答案是强制Maven重建。在Eclipse中:
这是因为StaticLoggerBinder.class类属于两个不同的jar。此类引用来自logback-classic-1.2.3.jar,同样的类也引用自log4j-slf4j-impl-2.10.0.jar。这两个jar都在classpath中。因此他们之间存在冲突。这是即使logpath [src / main / resource]中的log4j2.xml文件也不生成日志文件的原因。
我们选择了一个jar,我建议使用log4j-slf4j-impl-2.10.0.jar文件并排除logback-classic-1.2.3.jar文件。解决方案:打开pom文件并查看依赖关系Hierarchy [eclipse]或运行 mvn dependency:tree命令,用于查找依赖关系树和下载依赖关系的依赖关系源。找到冲突的依赖关系并排除它们。对于Springboot应用程序试试这个。
<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-actuator</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
This is working fine for me after struggling a lots.
似乎删除.m2目录和:
mvn install -DskipTests -T 4
为我解决了这个问题。
Gradle版;
configurations.all {
exclude module: 'slf4j-log4j12'
}
该错误可能会提供更多这样的信息(尽管您的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
。
在这个项目的pom.xml父文件夹中运行mvn dependency:tree
,给出:
现在选择你想要忽略的那个(可以消耗一个微妙的努力,我需要更多的帮助)
我决定不使用从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>
在上面的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")
)
<!--<dependency>-->
<!--<groupId>org.springframework.boot</groupId>-->
<!--<artifactId>spring-boot-starter-log4j2</artifactId>-->
<!--</dependency>-->
我通过删除这个解决了:spring-boot-starter-log4j2
只使用所需的依赖,而不是所有:)))。对我来说,对于日志记录过程的正常工作,您需要此依赖项从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>
... org.codehaus.mojo cobertura-maven-plugin 2.7 test ch.qos.logback logback-classic tools com.sun ...
##我修好了
... org.codehaus.mojo cobertura-maven-plugin 2.7 test ch.qos.logback logback-classic tools 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" />
从文件中删除这些条目(或者您可以重新生成它)修复了该问题。