【maven】排除maven中jar包依赖的解决过程 例子:spring cloud启动zipkin,报错maven依赖jar包冲突 Class path contains multiple SLF4J bindings.

一直对于maven中解决jar包依赖问题的解决方法纠结不清:

下面这个例子可以说明一个很简单的解决方法:

项目启动报错:

Connected to the target VM, address: '127.0.0.1:59412', transport: 'socket'
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/D:/document/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.10.0/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/D:/document/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.apache.logging.slf4j.Log4jLoggerFactory]
Exception in thread "main" java.lang.StackOverflowError

解决方案:

直接看报错内容,可以看出  是log4j和logback-classic的jar包冲突。

最简单的解决方法:将最新添加的jar包依赖,依次删除,然后启动服务,查看是因为多增加了哪个jar包依赖之后,出现的jar包冲突问题。

扫描二维码关注公众号,回复: 4198343 查看本文章

找到之后,在pom.xml中排除掉即可:

<!-- zipkin服务端 -->
        <dependency>
            <groupId>io.zipkin.java</groupId>
            <artifactId>zipkin-server</artifactId>
            <version>2.10.1</version>
            <!--排除-->
            <exclusions>
                <exclusion>
                    <groupId>org.apache.logging.log4j</groupId>
                    <artifactId>log4j-slf4j-impl</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

当然,排除的过程也可能依旧报错,那你得看看是你新加的这个jar包里面是多依赖了报错的jar包里的哪一个。

注意也可能是

   <!--排除-->
    <exclusions>
         <exclusion> 
         <groupId>ch.qos.logback</groupId>
         <artifactId>logback-classic</artifactId>
        </exclusion>
    </exclusions>

注意:

<groupId>对应上方错误中的红色
<artifactId>对应上方错误中的蓝色

猜你喜欢

转载自www.cnblogs.com/sxdcgaq8080/p/10007420.html