Maven类路径错误多个SLF4J绑定

问题描述 投票:0回答:2

我在尝试进行MAVEN安装时遇到了这个错误。我尝试了排除,但不确定在pom文件中包含的位置。让我知道如何以及在我的pom文件中包含哪些排除标记。我还附加了我的pom文件片段,其中包含exclusions`SLF4J:类路径包含多个SLF4J绑定。

SLF4J:在[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:在[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:请参阅http://www.slf4j.org/codes.html#multiple_bindings以获得解释。 SLF4J:实际绑定的类型为[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 -->
maven log4j maven-2 classpath slf4j
2个回答
4
投票

1运行

mvn dependency:tree

看哪个包导入org.slf4j

2保留一个,排除其他

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

0
投票

该消息表明您引入了logback-classic和log4j-slf4j-impl,它们都希望成为SLF4J绑定的日志框架。如果您不确定哪个依赖项带来了哪些其他依赖项,我发现运行“mvn dependency:tree”以查看正在使用的依赖项树是非常有用的。这应该为您提供足够的信息,以确定您需要排除哪个日志框架绑定。

正如documentation that the warning points to you所说,

嵌入式组件(如库或框架)不应声明对任何SLF4J绑定的依赖性,而仅依赖于slf4j-api。当库声明对SLF4J绑定的编译时依赖性时,它会对最终用户强制绑定,从而否定SLF4J的用途。当您遇到一个嵌入式组件声明对任何SLF4J绑定的编译时依赖关系时,请花时间联系所述组件/库的作者,并请他们修改他们的方法。

您非常希望从所有依赖项中排除所有实际日志记录框架,以便使用的唯一日志框架是您明确添加的日志框架。我甚至经常发现设置一些maven-enforcer-plugin bannedDependencies规则是有用的,以确保我在更新我的依赖项时不会意外引入另一个日志框架。在POM中使用dependencyManagement部分也很有帮助,以确保所有依赖项都使用相同版本的slf4j-api。

© www.soinside.com 2019 - 2024. All rights reserved.