栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

spring cloud 使用zookeeper作为注册中心—provider

spring cloud 使用zookeeper作为注册中心—provider

zookeeper安装参考:docker 安装kafka_诸葛子房的博客-CSDN博客

查看zk 信息:查看zk 信息_诸葛子房的博客-CSDN博客

1.pom 文件



    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        2.0.5.RELEASE
         
    
    com.example
    demo
    0.0.1-SNAPSHOT
    spring-cloud-provided
    Demo project for Spring Boot

    
        1.8
        Greenwich.RELEASE
    

    
        
            org.springframework.boot
            spring-boot-starter-web
        
        
        
            org.springframework.cloud
            spring-cloud-starter-zookeeper-discovery
            
                
                    org.apache.zookeeper
                    zookeeper
                
            
        
        
            org.apache.zookeeper
            zookeeper
            3.4.8
        

        
            org.springframework.boot
            spring-boot-starter-test
            test
        
    

    
        
            
                org.springframework.cloud
                spring-cloud-dependencies
                
                Finchley.RELEASE
                pom
                import
            
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    

    
        
            spring-milestones
            Spring Milestones
            https://repo.spring.io/milestone
            
            
                false
            
        
    



2.代码

package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

@EnableDiscoveryClient
@SpringBootApplication
public class SpringCloudProvidedApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringCloudProvidedApplication.class, args);
    }

}

3.配置文件

server.port=8001
###服务别名----服务注册到注册中心名称
spring.application.name=zk-provider
#zookeeper地址
spring.cloud.zookeeper.connect-string=127.0.0.1:2181

4.启动之后

看到zk 信息

zookeeper是采用临时节点类型的,也就是当服务关闭后,等待一会儿心跳收不到了zookeeper就会把服务信息剔除掉,没有自我保护机制的.

注意:spring boot 版本

参考:SpringCloud之使用Zookeeper作为注册中心_kxj19980524的博客-CSDN博客

完整代码:

zhugezifang/spring-cloud-provide (github.com)

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/389490.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号