一、问题说明
通过zookeeper的Node节点集群管理与Master选举客户端代码示例连接zookeeper-3.4.6服务端,运行后报"Exception in thread "main" org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /com/xwood/MasterElection/master"错误,详情日志>>
SLF4J: This version of SLF4J requires log4j version 1.2.12 or later. See also http://www.slf4j.org/codes.html#log4j_version@b@log4j:WARN No appenders could be found for logger (org.apache.zookeeper.ZooKeeper).@b@log4j:WARN Please initialize the log4j system properly.@b@Exception in thread "main" org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /com/xwood/MasterElection/master@b@ at org.apache.zookeeper.KeeperException.create(KeeperException.java:102)@b@ at org.apache.zookeeper.KeeperException.create(KeeperException.java:54)@b@ at org.apache.zookeeper.ZooKeeper.create(ZooKeeper.java:792)@b@ at zookeeper.master.Node1.<init>(Node1.java:23)@b@ at zookeeper.master.Node1.main(Node1.java:57)
二、解决方法
因服务端安装是zookeeper-3.4.6版本,代码中依赖包使用的zookeeper-3.4.13.jar,造成版本不一致导致无法连接,改为安装软件中zookeeper-3.4.6.jar版本,问题即可解决了(完整示例项目&依赖包可以到资源下载页面进行获取)。