java - 如何解决 log4j2 和 logback 冲突?
问题描述
各种方法都试过了,还是不行,哪里有问题!网上的各种方法都试过了,好烦!!!
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/E:/apache-maven/localrep/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:/E:/apache-maven/localrep/org/apache/logging/log4j/log4j-slf4j-impl/2.12.1/log4j-slf4j-impl-2.12.1.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]
Logging system failed to initialize using configuration from 'classpath:log4j2.xml'
java.lang.IllegalStateException: Logback configuration error detected:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
解决方案
您可以使用 Maven 依赖插件来查找依赖项的来源。
$ mvn dependency:tree -Dincludes=*:logback-classic:*,*:log4j-slf4j-impl:*
...
[INFO] --- maven-dependency-plugin:3.1.2:tree (default-cli) @ my-project ---
[INFO] com.example:my-project:jar:1.0-SNAPSHOT
[INFO] \- org.springframework.boot:spring-boot-starter-actuator:jar:2.2.6.RELEASE:compile
[INFO] \- org.springframework.boot:spring-boot-starter:jar:2.2.6.RELEASE:compile
[INFO] \- org.springframework.boot:spring-boot-starter-logging:jar:2.2.6.RELEASE:compile
[INFO] \- ch.qos.logback:logback-classic:jar:1.2.3:compile
...
如果要排除spring-boot-starter-logging
,则需要先添加显式spring-boot-starter
。
推荐阅读
- excel - 您可以在没有扩展名的情况下将变量引用/设置到工作簿吗?
- python - 如何启动 EC2 实例并按需运行任务
- oauth - Google Cloud OAuth 同意屏幕中的范围与调用 API 时请求的范围之间有什么关系?
- ruby-on-rails - 如何测试页面是否有日期选择器?
- android - 房间数据库查询后未触发实时数据观察器
- javascript - react-virtualized 网格从服务中检索图像,但直到滚动操作才呈现
- jquery - 使用引导表期间的详细视图不起作用
- authentication - asp.Net core 2.2中的多种身份验证方法
- scala - 火花数据集的问题
- sass - 将参数列表传递给 sass mixin 并从中组合一个值