Maven 类路径错误多个 SLF4J 绑定(bind)

标签 maven log4j maven-2 classpath slf4j

我在尝试进行 MAVEN 安装时遇到此错误。我尝试了排除,但不确定要包含在 pom 文件中的位置。让我告诉我应该如何以及在我的 pom 文件中包含哪些排除标签。我还附上了我的 pom 文件片段,其中包含排除`SLF4J:类路径包含多个 SLF4J 绑定(bind)。

SLF4J: Found binding in [jar:file:/C:/Users/147188/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: Found binding in [jar:file:/C:/Users/147188/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.10.0/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]

POM 文件:

<!-- Start of required part to make log4j work -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
    <exclusion>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
    </exclusion>
</exclusions> 
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>

    <exclusions>
    <exclusion>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
    </exclusion>
        <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-log4j2</artifactId>
    <exclusions>
    <exclusion>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
    </exclusion>
</exclusions> 
</dependency>
        <!-- End of required part to make log4j work -->

最佳答案

1次运行

mvn dependency:tree

查看哪个包导入了org.slf4j

2 保留一个,排除其他

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

关于Maven 类路径错误多个 SLF4J 绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51125553/

相关文章:

maven - 人工分类器元数据快照maven 3.0

tomcat - log4j配置加载

java - 如何使用 mercurial 和 maven(和 svn)嵌入修订信息

java - 如何将 CruiseControl 最新构建工件发布到静态 URL

java - 启动使用 jpackage 创建的已安装可执行文件时出现 ClassNotFoundException

Git for Windows(64 位)中的 Maven classworlds.launcher.Launcher 错误

java - 在 CI 环境中,在哪里保存 Maven 项目的 GPG key ?

java - Log4j 日志在没有 log4j.properties 的情况下显示在控制台上

java - Log4J2 (2.6) - 自动删除日志

maven-2 - 运行任务发布 Maven 安装