V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
xiaojianbang
V2EX  ›  Java

SpringBoot 项目中,第三方 jar 日志依赖冲突

  •  
  •   xiaojianbang · 2020-12-03 17:20:16 +08:00 · 2287 次点击
    这是一个创建于 1211 天前的主题,其中的信息可能已经有所发展或是发生改变。

    今天对接了移动短信 sdk,使用他们的 sdk 启动项目报错日志 SLF4J: Class path contains multiple SLF4J bindings.

    报错信息

    SLF4J: Class path contains multiple SLF4J bindings.
    SLF4J: Found binding in [jar:file:/Users/lf/work/company/code/dbs/src/main/resources/lib/masmgc.sdk.sms-0.0.1-SNAPSHOT.jar!/org/slf4j/impl/StaticLoggerBinder.class]
    SLF4J: Found binding in [jar:file:/Users/lf/javaweb/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.11.2/log4j-slf4j-impl-2.11.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]
    Exception in thread "main" java.lang.IllegalArgumentException: Cannot instantiate interface org.springframework.boot.SpringApplicationRunListener : org.springframework.boot.context.event.EventPublishingRunListener
    

    pom 文件

            <dependency>
                <groupId>com.yidong</groupId>
                <artifactId>yd-sms-sdk</artifactId>
                <version>0.0.1</version>
                <scope>system</scope>
                <systemPath>${project.basedir}/src/main/resources/lib/masmgc.sdk.sms-0.0.1-SNAPSHOT.jar</systemPath>
                <exclusions>
                    <exclusion>
                        <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-log4j12</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
    

    springboot 小项目日志使用的 log4j,引入的第三方 jar 无法排除,请教大佬们如何才能解决这个冲突。

    7 条回复    2020-12-03 20:47:48 +08:00
    lyusantu
        1
    lyusantu  
       2020-12-03 17:32:18 +08:00
    可以装个 maven 插件,排除一下是否有其他包也包含了第三方日志的其他版本,然后只保留一个就可以
    anansi
        2
    anansi  
       2020-12-03 17:33:13 +08:00
    这个不是老生常谈吗,通过 maven 的 show dependency,查看是哪些包引入了冲突的模块,然后在那些包 dependency 里一个个<exclusion>那个模块,最后只保留一个。大致就是这么改。
    liamyoung
        3
    liamyoung  
       2020-12-03 17:46:15 +08:00
    Idea 安装 maven helper 插件,去除相同的 slf4j 依赖,只保留一个
    1cming
        4
    1cming  
       2020-12-03 20:00:58 +08:00
    mvn dependency:tree 打印依赖树
    查看所有 SLF4J 相关的包
    逐一排除
    确认是否排除掉可以再次执行 mvn dependency:tree
    silentt
        5
    silentt  
       2020-12-03 20:16:45 +08:00 via iPhone
    移动短信 sdk 啊,我建议你用解压工具打开,直接把里面的 log4j 删了,那一个包里面啥都有,连 spring 都在 jar 里
    EastLord
        6
    EastLord  
       2020-12-03 20:47:18 +08:00
    跟我今天遇到的差不多 也是日志依赖冲突
    EastLord
        7
    EastLord  
       2020-12-03 20:47:48 +08:00
    我是把多余的依赖排除掉就好了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1969 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 16:22 · PVG 00:22 · LAX 09:22 · JFK 12:22
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.