有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java是否可以从POM中的依赖项中排除可传递的运行时范围依赖项?

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

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>

但是这似乎不起作用,但是我能够从SpringBootStarterWeb中排除依赖项,虽然可能是由于旧版本的原因,它没有使用属性日志记录,但它工作得很好。图案不再是控制台了

有人能建议在这种情况下该怎么办吗

我可以在依赖关系树中看到以下内容 enter image description here 但对于私有库/包,我看不到它内部有任何依赖关系,可能是因为它的依赖范围是运行时

注:我已更改回购的路径,因为它是私人回购


共 (0) 个答案