首页 > 解决方案 > 是否可以从 POM 中的依赖项中排除传递运行时范围依赖项?

问题描述

我有一个 Spring Boot 项目,它对 slf4j 和 log4j 具有运行时传递依赖。因此,我看到 slf4j 多重绑定警告,然后是 IllegalArgumentExceptionIllegalArgumentException。您可以在下面找到整个异常消息:

SLF4J: Found binding in [jar:file:/Users/pulkit/.m2/repository/com/xyz/platform/event/PlatformLibrary/1.0.1/PlatformLibrary-1.0.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/pulkit/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.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 [org.slf4j.impl.Log4jLoggerFactory]
[2021-03-04 08:41:59,594] INFO Kotlin reflection implementation not found at runtime, related features won't be available. (org.springframework.core.KotlinDetector)
Exception in thread "main" java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.slf4j.impl.Log4jLoggerFactory loaded from file:/Users/pulkit/.m2/repository/com/xyz/platform/event/PlatformLibrary/1.0.1/PlatformLibrary-1.0.1.jar). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.slf4j.impl.Log4jLoggerFacto

我阅读了与同一问题相关的其他答案,并尝试从平台库中排除 slf4j 绑定,这是一个私有仓库,但我似乎没有工作。下面是我在 pom.xml 中添加的排除块:

<dependency>
            <groupId>com.xyz.platform.event</groupId>
            <artifactId>PlatformLibrary</artifactId>
            <version>1.0.1</version>
<exclusions>
<exclusion>
   <groupId>org.slf4j</groupId>
   <artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
   <groupId>log4j</groupId>
   <artifactId>log4j</artifactId>
</exclusion>
</exclusions>

但这似乎不起作用,但是我可以从 spring-boot-starter-web 中排除依赖关系,虽然可能由于旧版本它不再需要使用属性 logging.pattern.console,但它工作正常。

有人可以建议在这种情况下可以做什么吗?

我可以在依赖树中看到以下内容, 在此处输入图像描述 但对于私有库/包,我在其中看不到任何依赖,可能是因为它的依赖范围是运行时。

注意:我已经更改了 repo 的路径,因为它是一个私人 repo。

标签: javaspring-bootmavendependenciestransitive-dependency

解决方案


推荐阅读