【问题标题】:SLF4J: Class path contains multiple SLF4J bindings Spring MavenSLF4J:类路径包含多个 SLF4J 绑定 Spring Maven
【发布时间】:2020-07-07 13:01:27
【问题描述】:

将 apache.mahout 添加到我的 pom.xml 后,我在运行我的 spring 项目时开始收到此警告,我想知道如何抑制此警告。

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/Kapio/.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/Kapio/.m2/repository/org/slf4j/slf4j-log4j12/1.7.30/slf4j-log4j12-1.7.30.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.xml

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.5.RELEASE</version>
        <relativePath/> 
    </parent>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>

            <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-mongodb</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>

        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>

        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.mahout</groupId>
            <artifactId>mahout-mr</artifactId>
            <version>0.10.0</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

我试图排除 slf4j-log4j12 但仍然无法正常工作并且每次都会收到警告

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

我到处查看,但无法删除警告。

有什么建议吗?

【问题讨论】:

  • 你在 GitHub/GitLab/Bitbucket 上有完整的工作示例吗?

标签: spring spring-boot maven logging slf4j


【解决方案1】:
  1. 您需要找出 引入了 slf4j-log4j。在 pom.xml 目录中的命令行上执行“mvn:dependency:tree”并找到将其拉入的依赖项。
  2. 将排除项放在该依赖项上。全局排除不起作用。
  3. 应该可以。

【讨论】:

  • 谢谢,我没有运行 mvn:dependency:tree 但我知道 mahout 正在使用它,所以我将它从依赖项 apache.mahout 中排除。
猜你喜欢
  • 2014-05-18
  • 1970-01-01
  • 2012-12-11
  • 2016-03-12
  • 2015-08-10
  • 2021-05-19
  • 1970-01-01
  • 2018-12-12
  • 2012-09-11
相关资源
最近更新 更多