1、安装zookeeper,并启动。
D:\apache-zookeeper\bin>.\zkServer.cmd
2、修改SpringBootTest
2.1、启动类添加@EnableDiscoveryClient,这将使SpringBootTest启动时自动注册。
2.2、在resources文件夹下添加application.yml,配置服务名称,zookeeper地址等信息。
spring:
application:
name: SpringBootTest
cloud:
zookeeper:
connect-string: localhost:2181
discovery:
enabled: true
server:
port: 8081
endpoints:
restart:
enabled: true
logging:
level:
org.apache.zookeeper.ClientCnxn: WARN
2.3、修改gradle.build文件,添加SpringCloud Zookeeper依赖包。
ext {
set('springCloudVersion', "Hoxton.SR1")
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
dependencies里添加
implementation 'org.springframework.cloud:spring-cloud-starter-zookeeper-discovery'
3、运行SpringBootTest-0.0.1-SNAPSHOT-boot.war,查看zookeeper注册情况。