I love the java series --- [springboot project as a zookeeper integrated registry]

1. introduced maven dependent

    <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
            <version>2.1.1.RELEASE</version>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.zookeeper</groupId>
                    <artifactId>zookeeper</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.zookeeper</groupId>
            <artifactId>zookeeper</artifactId>
            <Exclusions>
            <! - and the same server version installed Zookeeper ->
            <Version> 3.4.6 </ Version>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-log4j12</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

The above dependency into <dependencies> tag, into the following <dependencies> tag in the same directory

    <!--SpringCloud所有依赖管理的坐标-->
    <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>

2. On the springboot start classes with the comment: @EnableDiscoveryClient

3. Add disposed in yml

the Spring: 
  the Application: 
    # local test 
    name: dblocalhost 
    # test server 
    #NAME: DB 201 
  Cloud: 
    ZooKeeper: 
      Connect -string: 190.7.18.193:2181 
      #connect -string: localhost: 2181 
      Discovery: 
        Enabled: to true 
        the Register: to true 
        instance -host: spring.cloud.client.ip- {$ address} // start the service automatically obtain ip register to zk registry 
        # instance-host: 180.8.16.47 // can also write to die, it is recommended that the use of the above write 
        root: / after the name of the root node of sms // registration to zk

Guess you like

Origin www.cnblogs.com/hujunwei/p/12128755.html