1.下載zookeeper,修改/conf 的zoo_sample.cfg爲zoo.cfgspring
2.啓動bin/zkServer.cmdapp
3.加入整合依賴框架
<dependencies>
<!--省略其餘框架依賴-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Greenwich.SR1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
4.yml配置加入spa
server:
##服務端口
port: 6666
spring:
application:
##服務名稱
name: xxx-zk
cloud:
zookeeper:
##註冊到zookeeper地址
connect-string: 127.0.0.1:2181
5.啓動類加入註解code
@EnableDiscoveryClient
6.啓動項目,打開zooInspector查看是否已經註冊server