Springboot - Zookeeper配置
Springboot 版本 2.0.3.RELEASE
github : https://github.com/szjomin/SpringBootZookeeperConfig
一、java
pom 文件 - properties
<spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
pom 文件 - denpendenies
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-zookeeper-discovery</artifactId> </dependency> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <version>3.4.13</version> <exclusions> <exclusion> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>com.101tec</groupId> <artifactId>zkclient</artifactId> <version>0.10</version> <exclusions> <exclusion> <artifactId>slf4j-api</artifactId> <groupId>org.slf4j</groupId> </exclusion> <exclusion> <artifactId>log4j</artifactId> <groupId>log4j</groupId> </exclusion> <exclusion> <artifactId>slf4j-log4j12</artifactId> <groupId>org.slf4j</groupId> </exclusion> </exclusions> </dependency>
pom 文件 - dependencyManagement
<dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies>
2、注解
@EnableDiscoveryClient
在application上注解
3、配置文件
cloud:
zookeeper:
connect-string: 127.0.0.1:2181
discovery:
register: true
enable: true
instance-id: 1
root: /
二、启动zookeeper 服务
【 附:使用 zkui 实现 zookeeper 可视化 :https://www.cnblogs.com/zhangchengzi/p/10907595.html 】