一、客户端依赖
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.wangcj</groupId>
<artifactId>springcloud-zookeeper-member</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
</parent>
<!-- 管理依赖 -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.M7</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- SpringBoot整合Web组件 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- SpringBoot整合zookeeper客户端 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
</dependency>
</dependencies>
<!-- 注意: 这里必须要添加, 否者各种依赖有问题 -->
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/libs-milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</project>二、 APP类 使用@EnableDiscoveryClient 注解
@SpringBootApplication
//如果注册中心使用connsul和zookeeper使用此注解来注册服务
@EnableDiscoveryClient
public class ZkMemberApp {
public static void main(String[] args) {
SpringApplication.run(ZkMemberApp.class, args);
}
}三、yml文件配置上zookeeper服务端的信息:
###订单服务的端口号
server:
port: 8002
###服务别名----服务注册到注册中心名称
spring:
application:
name: zk-member
cloud:
zookeeper:
connect-string: 127.0.0.1:2181
版权声明:本文为u012758488原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。