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


    异常信息关键词:

    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]]

    详细异常信息:

    1. Connected to the target VM, address: '127.0.0.1:52687', transport: 'socket'
    2. SLF4J: Class path contains multiple SLF4J bindings.
    3. 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]
    4. 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]
    5. SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
    6. SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
    7. Logging system failed to initialize using configuration from 'classpath:log4j2.xml'
    8. java.lang.IllegalStateException: Logback configuration error detected:
    9. ERROR in ch.qos.logback.core.joran.spi.Interpreter@24:14 - no applicable action for [properties], current ElementPath is [[configuration][properties]]
    10. ERROR in ch.qos.logback.core.joran.spi.Interpreter@26:29 - no applicable action for [property], current ElementPath is [[configuration][properties][property]]
    11. ERROR in ch.qos.logback.core.joran.spi.Interpreter@28:31 - no applicable action for [property], current ElementPath is [[configuration][properties][property]]
    12. ERROR in ch.qos.logback.core.joran.spi.Interpreter@29:33 - no applicable action for [property], current ElementPath is [[configuration][properties][property]]
    13. ERROR in ch.qos.logback.core.joran.spi.Interpreter@30:36 - no applicable action for [property], current ElementPath is [[configuration][properties][property]]
    14. ERROR in ch.qos.logback.core.joran.spi.Interpreter@32:13 - no applicable action for [appenders], current ElementPath is [[configuration][appenders]]
    15. ERROR in ch.qos.logback.core.joran.spi.Interpreter@34:47 - no applicable action for [Console], current ElementPath is [[configuration][appenders][Console]]
    16. ERROR in ch.qos.logback.core.joran.spi.Interpreter@37:71 - no applicable action for [ThresholdFilter], current ElementPath is [[configuration][appenders][Console][ThresholdFilter]]
    17. ERROR in ch.qos.logback.core.joran.spi.Interpreter@38:44 - no applicable action for [PatternLayout], current ElementPath is [[configuration][appenders][Console][PatternLayout]]
    18. ERROR in ch.qos.logback.core.joran.spi.Interpreter@47:79 - no applicable action for [RollingFile], current ElementPath is [[configuration][appenders][RollingFile]]
    19. ERROR in ch.qos.logback.core.joran.spi.Interpreter@48:44 - no applicable action for [PatternLayout], current ElementPath is [[configuration][appenders][RollingFile][PatternLayout]]
    20. ERROR in ch.qos.logback.core.joran.spi.Interpreter@49:14 - no applicable action for [Policies], current ElementPath is [[configuration][appenders][RollingFile][Policies]]
    21. ERROR in ch.qos.logback.core.joran.spi.Interpreter@53:46 - no applicable action for [SizeBasedTriggeringPolicy], current ElementPath is [[configuration][appenders][RollingFile][Policies][SizeBasedTriggeringPolicy]]
    22. ERROR in ch.qos.logback.core.joran.spi.Interpreter@56:39 - no applicable action for [DefaultRolloverStrategy], current ElementPath is [[configuration][appenders][RollingFile][DefaultRolloverStrategy]]
    23. ERROR in ch.qos.logback.core.joran.spi.Interpreter@59:11 - no applicable action for [loggers], current ElementPath is [[configuration][loggers]]
    24. ERROR in ch.qos.logback.core.joran.spi.Interpreter@61:80 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]]
    25. 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]]
    26. ERROR in ch.qos.logback.core.joran.spi.Interpreter@64:109 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]]
    27. 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]]
    28. ERROR in ch.qos.logback.core.joran.spi.Interpreter@67:81 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]]
    29. 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]]
    30. ERROR in ch.qos.logback.core.joran.spi.Interpreter@71:79 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]]
    31. 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]]
    32. ERROR in ch.qos.logback.core.joran.spi.Interpreter@74:71 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]]
    33. 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]]
    34. ERROR in ch.qos.logback.core.joran.spi.Interpreter@77:87 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]]
    35. 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]]
    36. ERROR in ch.qos.logback.core.joran.spi.Interpreter@80:88 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]]
    37. 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]]
    38. ERROR in ch.qos.logback.core.joran.spi.Interpreter@83:80 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]]
    39. ERROR in ch.qos.logback.core.joran.spi.Interpreter@84:77 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]]
    40. 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]]
    41. ERROR in ch.qos.logback.core.joran.spi.Interpreter@87:84 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]]
    42. ERROR in ch.qos.logback.core.joran.spi.Interpreter@88:77 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]]
    43. 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]]
    44. ERROR in ch.qos.logback.core.joran.spi.Interpreter@92:55 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]]
    45. ERROR in ch.qos.logback.core.joran.spi.Interpreter@93:57 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]]
    46. ERROR in ch.qos.logback.core.joran.spi.Interpreter@94:65 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]]
    47. ERROR in ch.qos.logback.core.joran.spi.Interpreter@95:56 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]]
    48. ERROR in ch.qos.logback.core.joran.spi.Interpreter@96:64 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]]
    49. ERROR in ch.qos.logback.core.joran.spi.Interpreter@97:68 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]]
    50. ERROR in ch.qos.logback.core.joran.spi.Interpreter@98:64 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]]
    51. ERROR in ch.qos.logback.core.joran.spi.Interpreter@99:76 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]]
    52. ERROR in ch.qos.logback.core.joran.spi.Interpreter@100:72 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]]
    53. ERROR in ch.qos.logback.core.joran.spi.Interpreter@101:67 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]]
    54. ERROR in ch.qos.logback.core.joran.spi.Interpreter@102:52 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]]
    55. ERROR in ch.qos.logback.core.joran.spi.Interpreter@103:65 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]]
    56. ERROR in ch.qos.logback.core.joran.spi.Interpreter@104:66 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]]
    57. ERROR in ch.qos.logback.core.joran.spi.Interpreter@105:66 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]]
    58. ERROR in ch.qos.logback.core.joran.spi.Interpreter@106:62 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]]
    59. ERROR in ch.qos.logback.core.joran.spi.Interpreter@107:79 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]]
    60. ERROR in ch.qos.logback.core.joran.spi.Interpreter@110:61 - no applicable action for [Logger], current ElementPath is [[configuration][loggers][Logger]]
    61. 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]]
    62. 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]]
    63. ERROR in ch.qos.logback.core.joran.spi.Interpreter@116:23 - no applicable action for [root], current ElementPath is [[configuration][loggers][root]]
    64. 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]]
    65. 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]]
    66. at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:179)
    67. at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithSpecificConfig(AbstractLoggingSystem.java:66)
    68. at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:57)
    69. at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:132)
    70. at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:332)
    71. at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:298)
    72. at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:246)
    73. at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:223)
    74. at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)
    75. at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)
    76. at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)
    77. at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131)
    78. at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:85)
    79. at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:66)
    80. 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后运行项目可以正常启动了。

    1. org.springframework.boot
    2. spring-boot-starter-test
    3. test
    4. org.springframework.boot
    5. spring-boot-starter-logging

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

  • 相关阅读:
    竞赛选题 疲劳驾驶检测系统 python
    html5自定义属性--------Dataset
    Qt | UDP广播通信、简单使用案例
    【2023集创赛】Arm杯二等奖作品:基于Arm Cortex-M3的体感节奏音乐游戏机
    前端面经 前端优化
    记录一次clickhouse报错max_query_size超过最大限制
    COLMAP中将旋转矩阵转为四元数的实现
    智慧税务解决方案-最新全套文件
    k线图快速入门必读
    MySQL 查询条件
  • 原文地址:https://blog.csdn.net/lvbang_lzt/article/details/133633962