java - 是否可以从 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。
解决方案
推荐阅读
- vue.js - 数据达不到怎么办?
- c# - 使用“ApplyConfiguration”时,EF Core 迁移不起作用
- python - 如何从谷歌电子表格中提取数据到笔记本
- javascript - 是否可以将 HTML 代码放入 javascript 中的 innerHTML 中?
- apple-push-notifications - 通过 AirWatch REST API 推送通知?
- php - 在 Postman 上使用 Wordpress Nonce 作为 jQuery/Javascript 中的 setRequestHeader
- c - 如何使用问号对 sqlite 查询进行字符串化以查看将以文本形式执行的查询?
- ruby-on-rails - 使用 Devise 时注册失败如何保持在同一页面上?(注册表格显示在根页面上)
- sql - Oracle:相对日期和日期分区表
- python - 使用用户输入在另一个 python 文件中打印具有属性的 Python 类对象