转载

spring boot集成zookeeper解决包冲突

问题来源

在学习spring boot集成zookeeper构建微服务时,遇到了一个包冲突问题,下面报错表明

zookeeper-3.5.3-beta.jar这个包有问题,因为笔者主机下的zookeeper服务器版本是zookeeper-3.4.13

spring boot集成zookeeper解决包冲突

这个包下的org.apache.zookeeper:zookeeper:3.5.3-beta包是问题来源,要进行替换

spring boot集成zookeeper解决包冲突

spring boot集成zookeeper解决包冲突

问题解决

在原来的 spring-cloud-starter-zookeeper-discovery

<dependency>    
    <groupId>org.springframework.cloud</groupId>    
    <artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>    
    <exclusions>        
        <exclusion>            
            <groupId>org.apache.zookeeper</groupId>            
            <artifactId>zookeeper</artifactId>        
        </exclusion>    
    </exclusions>
</dependency>复制代码

添加对应zookeeper服务器的新包 org.apache.zookeeper:zookeeper:3.4.13

<dependency>    
    <groupId>org.apache.zookeeper</groupId>    
    <artifactId>zookeeper</artifactId>    
    <version>3.4.13</version>    
</dependency>复制代码

之后又出现了新的包冲突问题,slf4j与原包冲突,所以上面又添加了新的 <exclusions>

spring boot集成zookeeper解决包冲突

<dependency>    
    <groupId>org.apache.zookeeper</groupId>    
    <artifactId>zookeeper</artifactId>    
    <version>3.4.13</version>    
    <exclusions>        
        <exclusion>            
            <groupId>org.slf4j</groupId>            
            <artifactId>slf4j-api</artifactId>        
        </exclusion>        
        <exclusion>            
            <groupId>org.slf4j</groupId>            
            <artifactId>slf4j-log4j12</artifactId>        
        </exclusion>    
    </exclusions>
</dependency>复制代码

再次启动spring boot ,成功,YEAH!

spring boot集成zookeeper解决包冲突

原文  https://juejin.im/post/5e65026b518825492a7211db
正文到此结束
Loading...