依赖

  1. <!--SpringCloud整合Zookeeper,对应注解:@EnableDiscoveryClient-->
  2. <dependency>
  3. <groupId>org.springframework.cloud</groupId>
  4. <artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
  5. <exclusions>
  6. <!--先排除自带的zookeeper3.5.3-->
  7. <exclusion>
  8. <groupId>org.apache.zookeeper</groupId>
  9. <artifactId>zookeeper</artifactId>
  10. </exclusion>
  11. </exclusions>
  12. </dependency>
  13. <!--添加zookeeper3.4.14版本-->
  14. <dependency>
  15. <groupId>org.apache.zookeeper</groupId>
  16. <artifactId>zookeeper</artifactId>
  17. <version>3.4.14</version>
  18. </dependency>

配置

  1. server:
  2. port: 8081
  3. spring:
  4. application:
  5. name: zk-member
  6. cloud:
  7. zookeeper:
  8. connect-string: 127.0.0.1:2181

应用

@EnableDiscoveryClient
@SpringBootApplication
public class MyApp {
    public static void main(String[] args) {
        SpringApplication.run(MyApp.class, args);
    }
}