当前位置:网站首页>log4j-slf4j-impl cannot be present with log4j-to-slf4j
log4j-slf4j-impl cannot be present with log4j-to-slf4j
2022-08-03 22:22:00 【Master_Shifu_】
背景:
在修复logback远程执行漏洞时报错
log4j-slf4j-impl cannot be present with log4j-to-slf4j
这个错误的意思是 log4j-slf4j-impl 和 log4j-to-slf4j 这两个包不能同时存在。
那么为什么这两个包不能同时存在呢?我们先来看一下这两个包的定义:
log4j-slf4j-impl
Apache Log4j SLF4J Binding: The Apache Log4j SLF4J API binding to Log4j 2 Core
log4j-to-slf4j
Apache Log4j to SLF4J Adapter: The Apache Log4j binding between Log4j 2 API and SLF4J
从上述定义可以看出,log4j-slf4j-impl 主要是 log4j 对 slf4j 接口的实现,而 log4j-to-slf4j 则是 slf4j 对 log4j 接口的适配。
解决方案
1. 最复杂的方案是:逐个组件,挨个排查
如果springboot 项目使用log4j2日志框架,就将项目中引入 spring-boot-starter-logging及其引用jar 的地方,全部排查掉;或者继续使用springboot的logback,
那么就将log4j2 以及其jar的地方,通排查。— 耗时并且可能排查不干净
2. 使用pom全局排除
即将spring-boot-starter-logging 全部排除或者是将 spring-boot-starter-log4j2 的地方全部排除。
使用springboot 默认的logback 日志输出日志设置 :
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jul</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- 修复logback远程执行漏洞-->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.2.9</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.9</version>
<scope>compile</scope>
</dependency>
边栏推荐
猜你喜欢
中国企业构建边缘计算解决方案的最佳实践
2019年10月SQL注入的两倍
E-commerce data warehouse ODS layer-----log data loading
Network basic learning series four (network layer, data link layer and some other important protocols or technologies)
Embedded systems: overview
[b01lers2020]Life on Mars
生成器版和查看器版有什么区别?
如何创建一个Web项目
Diazo Biotin-PEG3-DBCO | Diazo Compound Modified Biotin-Tripolyethylene Glycol-Dibenzocyclooctyne
DO280管理和监控OpenShift平台--资源限制
随机推荐
YOLO之父宣布退出CV界,坦言无法忽视自己工作带来的负面影响
伴随着元宇宙、web3.0等概念的兴起,数字人、数字场景等诸多数字化的形态开始出现
Research status of target detection at home and abroad
UVa 1025 - A Spy in the Metro (White Book)
Flutter 桌面探索 | 自定义可拖拽导航栏
Teach a Man How to Fish - How to Query the Properties of Any SAP UI5 Control by Yourself Documentation and Technical Implementation Details Demo
L2-041 插松枝
授人以渔 - 如何自行查询任意 SAP UI5 控件属性的文档和技术实现细节试读版
for循环练习题
2022的七夕,奉上7个精美的表白代码,同时教大家快速改源码自用
Codeup刷题笔记-简单模拟
UVa 437 - The Tower of Babylon(白书)
目标检测的国内外研究现状
mysql如何将表结构导出到excel
藏宝计划TreasureProject(TPC)系统模式开发技术原理
PowerMockup 4.3.4::::Crack
[MySQL Advanced] Creation and Management of Databases and Tables
HCIP第十四天
Cisco ike2 IPSec配置
21天打卡挑战学习MySQL——《MySQL工具的使用》第一周 第二篇