Springboot项目log4j与logback的Jar包冲突问题

news/2024/11/15 2:38:06/

异常信息关键词:

SLF4J: Class path contains multiple SLF4J bindings.
ERROR in ch.qos.logback.core.joran.spi.Interpreter@24:14 - no applicable action for [properties], current ElementPath  is [[configuration][properties]]

详细异常信息:

Connected to the target VM, address: '127.0.0.1:52687', transport: 'socket'
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/xx/.m2/repository/ch/qos/logback/logback-classic/1.2.11/logback-classic-1.2.11.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/xx/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.17.2/log4j-slf4j-impl-2.17.2.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: 
ERROR in ch.qos.logback.core.joran.spi.Interpreter@24:14 - no applicable action for [properties], current ElementPath  is [[configuration][properties]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@26:29 - no applicable action for [property], current ElementPath  is [[configuration][properties][property]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@28:31 - no applicable action for [property], current ElementPath  is [[configuration][properties][property]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@29:33 - no applicable action for [property], current ElementPath  is [[configuration][properties][property]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@30:36 - no applicable action for [property], current ElementPath  is [[configuration][properties][property]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@32:13 - no applicable action for [appenders], current ElementPath  is [[configuration][appenders]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@34:47 - no applicable action for [Console], current ElementPath  is [[configuration][appenders][Console]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@37:71 - no applicable action for [ThresholdFilter], current ElementPath  is [[configuration][appenders][Console][ThresholdFilter]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@38:44 - no applicable action for [PatternLayout], current ElementPath  is [[configuration][appenders][Console][PatternLayout]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@47:79 - no applicable action for [RollingFile], current ElementPath  is [[configuration][appenders][RollingFile]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@48:44 - no applicable action for [PatternLayout], current ElementPath  is [[configuration][appenders][RollingFile][PatternLayout]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@49:14 - no applicable action for [Policies], current ElementPath  is [[configuration][appenders][RollingFile][Policies]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@53:46 - no applicable action for [SizeBasedTriggeringPolicy], current ElementPath  is [[configuration][appenders][RollingFile][Policies][SizeBasedTriggeringPolicy]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@56:39 - no applicable action for [DefaultRolloverStrategy], current ElementPath  is [[configuration][appenders][RollingFile][DefaultRolloverStrategy]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@59:11 - no applicable action for [loggers], current ElementPath  is [[configuration][loggers]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@61:80 - no applicable action for [Logger], current ElementPath  is [[configuration][loggers][Logger]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@62:33 - no applicable action for [appender-ref], current ElementPath  is [[configuration][loggers][Logger][appender-ref]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@64:109 - no applicable action for [Logger], current ElementPath  is [[configuration][loggers][Logger]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@65:33 - no applicable action for [appender-ref], current ElementPath  is [[configuration][loggers][Logger][appender-ref]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@67:81 - no applicable action for [Logger], current ElementPath  is [[configuration][loggers][Logger]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@68:33 - no applicable action for [appender-ref], current ElementPath  is [[configuration][loggers][Logger][appender-ref]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@71:79 - no applicable action for [Logger], current ElementPath  is [[configuration][loggers][Logger]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@72:33 - no applicable action for [appender-ref], current ElementPath  is [[configuration][loggers][Logger][appender-ref]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@74:71 - no applicable action for [Logger], current ElementPath  is [[configuration][loggers][Logger]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@75:33 - no applicable action for [appender-ref], current ElementPath  is [[configuration][loggers][Logger][appender-ref]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@77:87 - no applicable action for [Logger], current ElementPath  is [[configuration][loggers][Logger]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@78:33 - no applicable action for [appender-ref], current ElementPath  is [[configuration][loggers][Logger][appender-ref]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@80:88 - no applicable action for [Logger], current ElementPath  is [[configuration][loggers][Logger]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@81:33 - no applicable action for [appender-ref], current ElementPath  is [[configuration][loggers][Logger][appender-ref]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@83:80 - no applicable action for [Logger], current ElementPath  is [[configuration][loggers][Logger]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@84:77 - no applicable action for [Logger], current ElementPath  is [[configuration][loggers][Logger]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@85:33 - no applicable action for [appender-ref], current ElementPath  is [[configuration][loggers][Logger][appender-ref]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@87:84 - no applicable action for [Logger], current ElementPath  is [[configuration][loggers][Logger]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@88:77 - no applicable action for [Logger], current ElementPath  is [[configuration][loggers][Logger]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@89:33 - no applicable action for [appender-ref], current ElementPath  is [[configuration][loggers][Logger][appender-ref]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@92:55 - no applicable action for [Logger], current ElementPath  is [[configuration][loggers][Logger]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@93:57 - no applicable action for [Logger], current ElementPath  is [[configuration][loggers][Logger]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@94:65 - no applicable action for [Logger], current ElementPath  is [[configuration][loggers][Logger]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@95:56 - no applicable action for [Logger], current ElementPath  is [[configuration][loggers][Logger]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@96:64 - no applicable action for [Logger], current ElementPath  is [[configuration][loggers][Logger]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@97:68 - no applicable action for [Logger], current ElementPath  is [[configuration][loggers][Logger]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@98:64 - no applicable action for [Logger], current ElementPath  is [[configuration][loggers][Logger]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@99:76 - no applicable action for [Logger], current ElementPath  is [[configuration][loggers][Logger]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@100:72 - no applicable action for [Logger], current ElementPath  is [[configuration][loggers][Logger]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@101:67 - no applicable action for [Logger], current ElementPath  is [[configuration][loggers][Logger]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@102:52 - no applicable action for [Logger], current ElementPath  is [[configuration][loggers][Logger]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@103:65 - no applicable action for [Logger], current ElementPath  is [[configuration][loggers][Logger]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@104:66 - no applicable action for [Logger], current ElementPath  is [[configuration][loggers][Logger]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@105:66 - no applicable action for [Logger], current ElementPath  is [[configuration][loggers][Logger]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@106:62 - no applicable action for [Logger], current ElementPath  is [[configuration][loggers][Logger]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@107:79 - no applicable action for [Logger], current ElementPath  is [[configuration][loggers][Logger]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@110:61 - no applicable action for [Logger], current ElementPath  is [[configuration][loggers][Logger]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@111:33 - no applicable action for [appender-ref], current ElementPath  is [[configuration][loggers][Logger][appender-ref]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@112:29 - no applicable action for [appender-ref], current ElementPath  is [[configuration][loggers][Logger][appender-ref]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@116:23 - no applicable action for [root], current ElementPath  is [[configuration][loggers][root]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@117:33 - no applicable action for [appender-ref], current ElementPath  is [[configuration][loggers][root][appender-ref]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@119:29 - no applicable action for [appender-ref], current ElementPath  is [[configuration][loggers][root][appender-ref]]at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:179)at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithSpecificConfig(AbstractLoggingSystem.java:66)at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:57)at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:132)at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:332)at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:298)at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:246)at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:223)at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131)at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:85)at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:66)at java.util.ArrayList.forEach(ArrayList.java:1257)

异常信息告诉我们是jar包冲突导致,解决办法很简单,异常信息里面有个官网的地址,说明了解决方式,如下图:

访问地址:

http://www.slf4j.org/codes.html#multiple_bindings

传送门:SLF4J Error Codesicon-default.png?t=N7T8http://www.slf4j.org/codes.html#multiple_bindings

解决方式是指定使用的jar包,排除另一个不用的即可。

麻烦的是怎么找到导致jar冲突的依赖。

继续查看异常信息,提示了冲突的2个jar包的信息,如下截图:logback-classic和log4j-slf4j-impl。

查找jar依赖关系可以通过IDEA的maven插件,如下图直接搜索:

找到了相应的依赖包。

也可以通过树状结构查看,不如直接搜索来的直观:

或者通过maven命令查找:

dependency:tree -Dverbose -Dincludes=ch.qos.logback

找到导致冲突的依赖jar包,问题就好解决了,我这里是spring-boot-starter-test包导致的,直接排除springboot自带的logback即可,clean后运行项目可以正常启动了。

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope><!-- 排除自带的logback依赖 --><exclusions><exclusion><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-logging</artifactId></exclusion></exclusions>
</dependency>

每个项目导致的原因可能各不相同,这是我遇到的一次jar包冲突供参考。


http://www.ppmy.cn/news/1141508.html

相关文章

三十二、【进阶】hash索引结构

1、hash索引结构 &#xff08;1&#xff09;简述&#xff1a; hash索引&#xff0c;就是采用一定的hash算法&#xff0c;将键值换算成新的hash值&#xff0c;映射到对应的槽位上&#xff0c;然后存储在hash表中。 &#xff08;2&#xff09;图示&#xff1a; 2、hash索引结构…

探索 GAN 和 VAE 之外的 NLP 扩散模型

介绍 扩散模型最近引起了极大的关注,特别是在自然语言处理(NLP)领域。基于通过数据扩散噪声的概念,这些模型在各种NLP任务中表现出了卓越的能力。在本文中,我们将深入研究扩散模型,了解其基本原理,并探讨实际应用、优势、计算注意事项、扩散模型在多模态数据处理中的相…

从入门到精通,30天带你学会C++【第七天:for循环和while循环以及数组的学习】(学不会你找我)

目录 Everyday English 前言 数组 数组的概念 数组的定义 数组的下标 for循环 循环是什么 基本格式 多重循环 while循环 do-while循环 总结 Everyday English To shine , not be illuminated. 去发光&#xff0c;而不是被照亮。 前言 好久不见&#xff0c…

Spring源码解析——IOC属性填充

正文 doCreateBean() 主要用于完成 bean 的创建和初始化工作&#xff0c;我们可以将其分为四个过程&#xff1a; 最全面的Java面试网站 createBeanInstance() 实例化 beanpopulateBean() 属性填充循环依赖的处理initializeBean() 初始化 bean 第一个过程实例化 bean在前面一篇…

SpringCloud学习笔记-Eureka的服务拉取

假设是OrderService里面拉取Eureka的服务之一User Service 1.依然需要在该服务里面引入依赖 <dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependenc…

【Oracle】Oracle系列之十七--Sqluldr2与Sqlldr

文章目录 往期回顾1. Sqluldr2导出文本2. Sqlldr导入文本 往期回顾 【Oracle】Oracle系列之一–Oracle数据类型 【Oracle】Oracle系列之二–Oracle数据字典 【Oracle】Oracle系列之三–Oracle字符集 【Oracle】Oracle系列之四–用户管理 【Oracle】Oracle系列之五–Oracle表…

Integer i1 = 128;Integer i2 = 128;boolean b = i1 == i2; 是ture 还是 false

自动装箱&#xff0c;是把一个 基础类型 比如 int 包装成一个 对象类型Integer&#xff0c;先不讨论这是怎么实现的。 那么&#xff0c;如题的答案是 true 还是 false呢&#xff1f; 看一下 Integer 类&#xff0c;内置了一个 Integer类型的数组。如下&#xff0c;这个数组就是…

【Cents OS7 安装 Docker以及DockerCompose】

文章目录 0.安装Docker1.CentOS安装Docker1.1.卸载&#xff08;可选&#xff09;1.2.安装docker1.3.启动docker1.4.配置镜像加速 2.CentOS7安装DockerCompose2.1.下载2.2.修改文件权限2.3.Base自动补全命令&#xff1a; 3.Docker镜像仓库3.1.简化版镜像仓库3.2.带有图形化界面版…