1.config服务端配置

1.1 引入依赖

        <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>

1.2 配置项application.yml

spring:
cloud:
zookeeper:
connect-string: 192.168.220.128:2181
config:
server:
git:
uri: https://gitee.com/lm970585581/cloud-config
username: lm970585581
password: ***** #密码

1.3 启动类配置

@EnableConfigServer 启用服务配置

测试说明:

/{label}/{name}-{profiles}.yml
/{name}-{profiles}.yml
name git的文件名称不包括后缀
profiles 环境
label 分支(branch)

2、客户配置:provider应用

2.1 引入依赖

        <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>

2.2 配置项bootstrap.yml

spring:
cloud:
zookeeper:
connect-string: 192.168.220.128:2181
config:
discovery:
enabled: true
service-id: config #配置服务项目名
profile: dev
application:
name: provider

Spring Cloud Bus 手动实现刷配置(不重启项目情况下)

1.安装RabbitMQ

详见:https://www.cnblogs.com/lm970585581/p/9873391.html

2.配置端引入依赖

        <!--加入spring cloud bus + rabbitmq-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>

3.配置端配置application.yml

spring:
rabbitmq:
port: 5672
host: 192.168.220.128
username: test
password: root
management:
endpoints:
web:
exposure:
include: '*' # 开启所有配置url

4.在controller上启用读取刷新数据注解@RefreshScope

此时,当git上的配置修改后,配置应用的内容会同步修改

客户端应用的配置需要手动使用Post方式刷新,即可同步修改,无需重启服务,格式如下:地址是配置应用的地址

http://localhost:8080/actuator/bus-refresh

Spring Cloud Bus 实现自动刷配置(不重启项目情况下)+WebHooks

加入依赖

        <!--添加支持gitlab,github,gitee webhooks依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-monitor</artifactId>
</dependency>

想办法把自己机器变为服务器,可以使用netaap

在gitee里面配置webhook

通过/monitor 接口回调目标服务对应的服务

注意:自动刷新方式有BUG存在,可能会失败,等官方修复吧!

具体实例详见:https://gitee.com/lm970585581/cloud-config

码云上的配置信息

Spring Cloud Config的更多相关文章

  1. Spring Cloud面试题万字解析(2020面试必备)

    1.什么是 Spring Cloud? Spring cloud 流应用程序启动器是 于 Spring Boot 的 Spring 集成应用程序,提供与外部系统的集成.Spring cloud Tas ...

  2. 什么是 Spring Cloud Bus?我们需要它吗?

    考虑以下情况:我们有多个应用程序使用 Spr ng Cloud Config 读取属性,而S ring Cloud Config 从GIT 读取这些属性. 下面的例子中多个员工生产者模块从 Employe ...

  3. Spring Cloud Greenwich 新特性和F升级分享

    2019.01.23 期待已久的Spring Cloud Greenwich 发布了release版本,作为我们团队也第一时间把RC版本替换为release,以下为总结,希望对你使用Spring Cl ...

  4. Spring Cloud 学习 之 Spring Cloud Bus实现修改远程仓库后配置自动刷新

    ​ 版本号: ​ Spring Boot:2.1.3.RELEASE ​ Spring Cloud:G版 ​ 开发工具:IDEA 搭建配置中心,这里我们搭建一个简单版的就行 POM: <?xml ...

  5. Kafka及Spring Cloud Stream

    安装 下载kafka http://mirrors.hust.edu.cn/apache/kafka/2.0.0/kafka_2.11-2.0.0.tgz kafka最为重要三个配置依次为:broke ...

  6. Microservices Reference Architecture - with Spring Boot, Spring Cloud and Netflix OSS--转

    原文地址:https://www.linkedin.com/pulse/microservices-reference-architecture-spring-boot-cloud-anil-alle ...

  7. Building microservices with Spring Cloud and Netflix OSS, part 2

    In Part 1 we used core components in Spring Cloud and Netflix OSS, i.e. Eureka, Ribbon and Zuul, to ...

  8. Spring cloud项目实践(一)

    链接地址:http://sail-y.github.io/2016/03/21/Spring-cloud%E9%A1%B9%E7%9B%AE%E5%AE%9E%E8%B7%B5/ 什么是Spring ...

  9. 【译文】用Spring Cloud和Docker搭建微服务平台

    by Kenny Bastani Sunday, July 12, 2015 转自:http://www.kennybastani.com/2015/07/spring-cloud-docker-mi ...

随机推荐

  1. 20155218 2006-2007-2 《Java程序设计》第2周学习总结

    20155218 2006-2007-2 <Java程序设计>第2周学习总结 教材学习内容总结 java编程风格: java中没有指针的概念,尽管也有数组和对象的引用的概念,但他的管理全部 ...

  2. 与虚拟机和linux的初次接触

    初次接触虚拟机 根据老师所给的资源和教程,虚拟机安装的过程十分顺利. 接下来是在虚拟机上安装linux操作系统我下载了破解版的Ubuntu,也是十分顺利 接下来就是安装虚拟机增强功能,命令有些繁琐,在 ...

  3. 20155307 实验四 Android程序设计

    在安装as的过程中一路顺风,一点问题都没有,但是在编译的时候总是出现错误,无论是我用自己的手机还是虚拟的手机都不能成功. 但是我上网百度,发现错误原因为compileSdkVersion的版本出了问题 ...

  4. day 13 字典dict 操作

    1.len   键值对的个数 In [4]: nums = [11,22,33] In [6]: len(nums) Out[6]: 3 In [7]: infor = {"name&quo ...

  5. jenkins自动打包部署linux

    需要用到2个插件. git parameter:用于参数化构建时选择分支. Publish Over SSH:用于上传jar包和操作tomcat 1.先在系统设置添加要连接的linux服务器,使用用户 ...

  6. stl源码分析之allocator

    allocator封装了stl标准程序库的内存管理系统,标准库的string,容器,算法和部分iostream都是通过allocator分配和释放内存的.标准库的组件有一个参数指定使用的allocat ...

  7. 获取label标签内for的属性值-js

    <body> <div class="row_2" id="ass"> <label for="aaa"> ...

  8. 如何开发一个 PyCharm 插件

    PyCharm 是很多 Python 开发者优先选择的 IDE,功能强大,跨平台,提供免费社区版,非常良心.如果你想自己给PyCharm添加一些功能怎么办呢?有两个办法: 通过提需求实现,到 JetB ...

  9. Python爬虫入门(7):正则表达式

    下面就开始介绍一个十分强大的工具,正则表达式! 1.了解正则表达式 正则表达式是对字符串操作的一种公式,就是用事先定义好的一些特定字符.及这些特定字符的组合,组成一个“规则字符串”,这个“规则字符串” ...

  10. 全国城市一卡通一级TSM平台业务架构及意义

    [导读]TSM平台是一种具有鲜明行业属性的平台,因此,各行业都建立了本行业的TSM平台.为促进城市一卡通行业移动支付的快速发展,住房和城乡建设部也建立了全国城市一卡通行业一级TSM平台. 作为住建部标 ...