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. 201555334 实验一:Java开发环境的熟悉 总结

    201555334 实验一:Java开发环境的熟悉 一.实验目的: 使用JDK编译.运行简单的Java程序: 使用Idea软件 编辑.编译.运行.调试Java程序. 二.实验内容: 编程实现让用户输入 ...

  2. 20145209 实验一《Java开发环境的熟悉》实验报告

    20145209 实验一<Java开发环境的熟悉>实验报告 实验内容 1.使用JDK编译.运行简单的Java程序. 2.使用Eclipse 编辑.编译.运行.调试Java程序. 提交 Li ...

  3. c++ 参数个数可变的函数

    #include <stdio.h> #include <string.h> #include <stdarg.h> int addnum(int i,...) { ...

  4. day6 网络 HTML模板

    1.HTML模板 HTML模板 baidu一下 http://www.cssmoban.com/ http://www.cnblogs.com/web-d/archive/2010/04/16/171 ...

  5. Apache入门篇(一)之安装部署apache

    一.HTTPD特性 (1)高度模块化:core(核心) + modules(模块) = apache(2)动态模块加载DSO机制: Dynamic Shared Object(动态共享对象)(3)MP ...

  6. java nio通过ByteBuffer输出文件信息

    1.通过ByteBuffer的get()方法每次读取一个字节转换成char类型输出. fc = new FileInputStream("src/demo20/data.txt") ...

  7. mybatis按datetime条件查询,参数为时间戳时

    mybatis按datetime条件查询,参数为时间戳时,如果数据库为2018-1-1 20:22:10, 你的时间戳也为2018-1-1 20:22:10,但却没找到数据.可能是时差导致的.百度修正 ...

  8. C#入门经典第十章例题 - - 卡牌

    1.库 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ...

  9. CsvHelper文档-5配置

    CsvHelper文档-5配置 CsvHelper库被设计成快速且简单易用,但是有时候默认的是设置不符合要求,需要你自己改变一些东西.所以csvHelper内置了很多自定义设置选项来改变读写行为.特别 ...

  10. 基于zookeeper+mesos+marathon的docker集群管理平台

    参考文档: mesos:http://mesos.apache.org/ mesosphere社区版:https://github.com/mesosphere/open-docs mesospher ...