在导入 curator-recipes 包时,与zookeeper出现兼容性问题,4.0以上版本 curator-recipes 包与3.5.x版本的zookeeper服务相匹配,与3.4.x版本的zookeeper不兼容。解决方案如下:
ZooKeeper 3.4.x
去除包中的org.apache.zookeeper包,在导入与zookeeper服务版本服务相兼容版的zookeeper包,同时去除包中的日志包,否则会与springboot本身的日志包相互冲突,如下所示。
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>4.2.0</version>
<exclusions>
<exclusion>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.12</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
ZooKeeper 3.5.x
zookeeper版本为3.5.x,直接导入4.0以上版本 curator-recipes 的就可以,不会有异常冲突
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>4.2.0</version>
</dependency>