SpringBoot启动报错:LoggerFactory is not a Logback LoggerContext but Logback is on the classpath

Error(13) 解决LoggerFactory is not a Logback LoggerContext but Logback is on the classpath 错误日志 Caused by: 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:/E:/IT_zhengqi 阅读详情
AI摘要

本文解决因SLF4J包冲突导致的日志打印问题,详细介绍了如何通过编辑pom.xml文件排除多余包,确保日志系统正常运行。

这个问题是slf4j包冲突所产生的问题,本博调试过程借鉴了下面链接所述博客,但情况与其不尽相同,博客将通过两种方式进行包的排除。

https://juejin.im/entry/5b6927906fb9a04fb900f611

目录

一、日志信息及错误

二、编辑pom.xml文件进行包的调整

三、直接在IDEA依赖图中进行修改
一、日志信息及错误

1、完整日志

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/zhanggong004/.m2/repository/org/slf4j/slf4j-log4j12/1.7.25/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/zhanggong004/.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]
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:/C:/Users/zhanggong004/.m2/repository/org/slf4j/slf4j-log4j12/1.7.25/slf4j-log4j12-1.7.25.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.Log4jLoggerFactory
	at org.springframework.util.Assert.instanceCheckFailed(Assert.java:655)
	at org.springframework.util.Assert.isInstanceOf(Assert.java:555)
	at org.springframework.boot.logging.logback.LogbackLoggingSystem.getLoggerContext(LogbackLoggingSystem.java:286)
	at org.springframework.boot.logging.logback.LogbackLoggingSystem.beforeInitialize(LogbackLoggingSystem.java:102)
	at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationStartingEvent(LoggingApplicationListener.java:220)
	at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:199)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
	at org.springframework.boot.context.event.EventPublishingRunListener.starting(EventPublishingRunListener.java:69)
	at org.springframework.boot.SpringApplicationRunListeners.starting(SpringApplicationRunListeners.java:48)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:302)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
	at com.example.dubboconsumer.DubboConsumerApplication.main(DubboConsumerApplication.java:13)

2、可以通过日志信息发现,两个jar包中的方法产生了冲突。

C:/Users/zhanggong004/.m2/repository/org/slf4j/slf4j-log4j12/1.7.25/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]

C:/Users/zhanggong004/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class

 当前使用的是org里的包,正常的日志打印需要的是logback的包

二、编辑pom.xml文件进行包的调整

1、根据一中的报错情况,我们在项目对应的pom.xml中增加了包,包的版本以实际情况设置

<dependency>
   <groupId>ch.qos.logback</groupId>
   <artifactId>logback-classic</artifactId>
   <version>1.2.3</version>
</dependency>

2、同时,在原有的包后注明不再使用slf4j-log4j12方法。

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
    <groupId>com.101tec</groupId>
    <artifactId>zkclient</artifactId>
    <version>0.10</version>
    <exclusions>
        <exclusion>
            <artifactId>slf4j-log4j12</artifactId>
            <groupId>org.slf4j</groupId>
        </exclusion>
    </exclusions>
</dependency>

  分别改为

<dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-web</artifactId>
     <exclusions>
          <exclusion>
               <groupId>org.slf4j</groupId>
               <artifactId>slf4j-log4j12</artifactId>
          </exclusion>
     </exclusions>
</dependency>

<dependency>
    <groupId>com.101tec</groupId>
    <artifactId>zkclient</artifactId>
    <version>0.10</version>
    <exclusions>
        <exclusion>
            <artifactId>slf4j-log4j12</artifactId>
        </exclusion>
    </exclusions>
</dependency>
SpringBoot项目报错:LoggerFactory is not a Logback LoggerContext but Logback is on the classpath 插件,在IDEA的setting中找见Plugins下载安装,重启IDEA,重启后选中你要查看的pom文件,右键,选择:Dependency Analyzer,然后所有的依赖传递都会显示出来,再搜索框搜索你需要搜索的,如我这里slf4j,搜索见之后,点击,右侧就会出现对应的封装的相关依赖,再回到pom文件中找见对应的依赖,在依赖下加入上述依赖排除标签即可。分析:项目中有些依赖底层会封装此日志依赖,所以使用了封装了此依赖的依赖,虽然没有主动加slf4j依赖,也会报日志冲突的相关错误;一,移除slf4j; 阅读详情

相关推荐

报错:Exception in thread “main“ java.lang.IllegalArgumentException...如何解决?

🏆 本文收录于《全栈Bug调优(实战版)》专栏,致力于分享我在项目实战过程中遇到的各类Bug及其原因,并提供切实有效的解决方案。无论你是初学者还是经验丰富的开发者,本文将为你指引出一条更高效的Bug修复之路,助你早日登顶,迈向财富自由的梦想🚀!同时,欢迎大家关注、收藏、订阅本专栏,更多精彩内容正在持续更新中。让我们一起进步,Up!Up!Up!    备注: 部分问题/难题源自互联网,但经过精心筛选和整理,保证每一条解决方案都经过实战验证,真实可靠。

**My Coding Family** 2702

LoggerFactory is not a Logback LoggerContext but Logback is on the classpath

2. 如果你无法移除其他日志库的依赖,可以尝试排除冲突的依赖项。具体方法取决于你使用的构建工具和依赖管理系统。例如,如果你使用Maven,可以在对应依赖项的声明中添加``标签,将冲突的依赖项排除掉。如果你同时引入了Logback和其他日志库的依赖,可以尝试将其他日志库的依赖移除,只保留Logback的依赖。这个错误是由于在你的Java代码中使用了Logback日志库,但是同时又存在与Logback竞争的其他日志库(例如slf4j-simple)导致的冲突。排除掉冲突的jar包即可。

小白菜 1万+

图文带你理解什么是Few-shot Learning

Few-shot Learning(少样本学习)是Meta Learning(元学习)中的一个实例1,所以在了解什么是Few-shot Learning之前有必要对Meta Learning有一个简单的认识。不过在了解什么是Meta Learning之前还是要了解一下什么是Meta。因此,阅读本文后你将对如下知识有一个初步的了解。 What is Meta What is Meta Learning What is Few-shot Learning 1. What is Meta? meta就是描述

Pr4da的博客 1万+

Tomcat启动Springboot项目,报错LoggerFactory is not a Logback LoggerContext but Logback is on the classpath.

今天用Tomcat启动springboot打的war包时,报如下错误: SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/home/app/tomcat80/webapps/henry/WEB-INF/lib/slf4j-simple-1.7.22.jar!/org/slf4...

qq_33996921的博客 1374

吉比特-笔试

1. 题一:打雷后下雨的概率是80%,而打闪电后下雨的概率是70%,那么即打雷又打闪电后下雨的概率是多少?   答:打雷后下雨和打闪电后下雨都是独立事件,P=1-又打雷又闪电但没下雨的概率= 1 - 0.2 *0.3 = 94%        题二:打雷后下雨的概率是80%,但是没打闪电后下雨的概率是20%,那么打雷了但没打闪电后下雨的概率是多少?答:P=0.8 *0.2 / ( 0.8 *0

naturism的专栏 2495

费斯托SPAN压力传感器的调试

本体为压力传感器,检测气压大小,通过设置参数,在上电上气时对气压进行判断,进而通过自身逻辑的判断,控制传感器的通断,进而控制机械部位的工作与运行;通电之后为如下图所示的样子有三个按键ABEdit键(编辑键、确认键)两步即可轻松连接。

大小曲奇的博客 1万+

SpringBoot项目启动报错:LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Eithe

使用SpringBoot3.0.9开发,引入依赖。

哈 1196

Dify工作流构建案例:迭代驱动的多维深度搜索

为了克服这些挑战,我们可以设计一个能够智能协同内部知识库与外部互联网搜索,并最终由大型语言模型(LLM)进行深度整合与精准回答的高级工作流。

同名公众号:dify实验室 2291

Springboot启动报错:LoggerFactory is not a Logback LoggerContext but Logback is on the classpath.

我索性在他的父级模块modules上加了2.0.4的slf4j-api。本次报错原因是启动的时候因为slf4jjar包冲突报错。但是我并没有在system模块下找到该jar包。冲突的jar包在system模块下。

m0_49969326的博客 616

国网DLT698.45协议——采集系统、数据交换(三)

物理层规定了通信单元或其他终端设备与多功能电表的通信接口,接口的物理与电气特性。常见的物理层传输方式有对于RS485、红外、载波通信等通信信道。将数据包装成可传输的帧格式。1、根据通信配置参数完成端口的初始化配置,通信状态初始化为准备接收状态,初始化相关计数器及缓冲区指针。2、链路层及控制子模块负责通信数据的收发控制,各类超时问题的处理。无通信数据接收时,定时初始化通信端口。3、完成协议帧的解析及应答。

一个bug是bug,多个bug能work 8050

V-Mamba:2D 选择性扫描状态空间模型图像分类

V-Mamba CIFAR-10 分类链路:32² RGB → Stem Conv (3→64ch, stride2→16²) → VMambaBlock ×4 (SS2D 四方向 → Mamba S6 扫描 → MLP) → GAP → Linear → 10 类。核心贡献:SS2D 四方向扫描将 2D 空间建模转为 4 个 1D 序列, 计算复杂度从 O(N²) 降至 O(N)。建议先从 CIFAR-10 dim=64 depth=4 验证 SSM 收敛性;

FJN110的博客 70

Error:Springboot启动报错:LoggerFactory is not a Logback LoggerContext but Logback is on the classpath.

1.问题描述 启动WebApplication就会报错 Exception in thread "main" java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the...

小蚯蚓的博客 3243

【YOLOv11改进- 主干网络】YOLOv11+WTConv(ECCV2024): 基于YOLOv11的主干网络改进,大感受野的小波卷积

论文提出了WTConv,这是一个使用级联小波分解的层,并执行一组小卷积核的卷积,每个卷积专注于输入的不同频率带,并具有越来越大的感受野。这个过程能够在输入中对低频信息给予更多重视,同时仅增加少量可训练参数。实际上,对于一个  的感受野,可训练参数数量只随着  的增长而呈对数增长。而WTConv与常规方法的参数平方增长形成对比,能够获得有效的卷积神经网络(CNN),其有效感受野(ERF)大小前所未有。

qq_41304809的博客 1401

springboot 报错“LoggerFactory is not a Logback LoggerContext but Logback is on the classpath.” 解决方式

springboot 项目启动server子模块时,报了 "Exception in thread "main" java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or ...

qq_20134605的博客 1万+

Oracle EBS Interface/API(42) -AP发票客制化付款申请

背景 在OA系统上,选择Oracle EBS的某张AP发票做付款申请,需要类似于锁定该发票以便付款,其他用户或者下次用户不能再次选择该发票做付款申请。 快速参考 参考点 内容 功能导航 N: AP->Invoices->Entry>Invoices 并发请求 None 基表 AP.AP_INV_SELECTION_CRITERIA_ALLAP.AP_SELECTED_INVOICES_ALL API 参考下面介绍 错误信息表 None 接口Form

陈显平的专栏-Oracle EBS 1200

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

springboot 中报错“LoggerFactory is not a Logback LoggerContext but Logback is on the classpath...” 解决方式

springboot 中报错“LoggerFactory is not a Logback LoggerContext but Logback is on the classpath...” 解决方式

pythonYY的博客 2635

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

关于Spring Boot报错:LoggerFactory is not a Logback LoggerContext but Logback is on the classpath

一、问题的现象 1、使用spring-boot-starter-web重构项目时,遇到报错: SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/C:/Users/mou/.m2/repository/org/slf4j/slf4j-log4j12/1.7.30/slf4j-log4j12-1.7.30.jar!/org/slf4j/impl/StaticLoggerBinder.cla

weixin_42717117的博客 1万+

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

SLF4J 异常,LoggerFactory is not a Logback LoggerContext but Logback is on the classpath.

再次启动项目,成功启动。

dingxiao123的博客 790

SpringBoot启动:LoggerFactory is not a Logback LoggerContext but Logback is on the classpath

报错信息: SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/C:/Users/.m2/repository/org/slf4j/slf4j-log4j12/1.7.25/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/C:/.

D的博客 1573

LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback

springboot项目启动报错,SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/D:/.m2/repository-tenacity/org/slf4j/slf4j-reload4j/1.7.36/slf4j-reload4j-1.7.36.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in

零度念者的博客 389

LoggerFactory is not a Logback LoggerContext but Logback is on the classpath.

启动Spring Boot项目时,报错: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.slf4j.impl.LogFactoryImpl loaded from file:/Users/hao/.m2/repository/com/fireflysource/firef

haoranhaoshi的博客 1882
上一篇: service redis does not support chkconfig的解决办法
下一篇: Eureka配置对服务下线后快速感知配置
qq_34412985
博客等级 码龄11年 143粉丝 983原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值