SpringCloud(5) SpringCloudConfig分布式配置中心【搭建服务端和客户端】

前言:微服务架构中,每个项目都有一个yml配置,管理起来麻烦。可以使用spring cloud config来统一管理

 Spring Cloud Config是什么?

      在分布式系统中,由于服务数量巨多,为了方便服务配置文件统一管理,实时更新,所以需要分布式配置中心组件。在Spring Cloud中,有分布式配置中心组件spring cloud config ,它支持配置服务放在配置服务的内存中(即本地),也支持放在远程Git仓库中。在spring cloud config 组件中,分两个角色:①config server,②config client

架构:

能干什么?

 Spring Cloud Config 和 github集成

温馨小提示:可以和svn,git集成,但是推荐使用github 集成使用

一、服务端配置

1.github创建配置文件 https://github.com/zhengqingya/microservice-config/blob/master/application-user.yml

2.创建springboot项目并且导入jar  

<dependencies>
    <!--springboot支持-->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
    </dependency>
    <!-- eureka客户端 -->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>
    <!--配置中心支持-->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-config-server</artifactId>
    </dependency>
</dependencies>

3.代码方面:

4.测试:启动 

http://127.0.0.1:1299/application-user/dev 和 http://127.0.0.1:1299/application-user/test

 

温馨小提示:这里实际上访问的是如下application-user 

二、客户端配置

1.创建普通maven项目:

2.导入依赖:

<dependencies>
    <!--公共依赖-->
    <dependency>
        <groupId>com.zhengqing.springcloud</groupId>
        <artifactId>User_interface</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
    <!--springboot支持-->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
    </dependency>
    <!--eureka客户端支持 -->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>
    <!--配置中心支持-->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-config</artifactId>
    </dependency>
</dependencies>

3.代码方面:

4.测试:启动  、  、

看控制台端口

Eureka上面名字

最后小结:

①搭建服务端  去访问github上面的统一管理的配置,注册到注册中心

②搭建客户端  通过服务端直接去拿到github上面的配置

【注意:除了configserver,Eureka不用以外,其他都要通过configserver到github上面去获取,以后要维护我们的配置就可以去维护github上面的仓库即可,就达到了我们的配置中心统一管理的效果】


最后附上项目源码:https://pan.baidu.com/s/1yefiPZ_HqQIJN0Ibvlq2KA

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

郑清

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值