springcloud ---springcloud Bus自动更新配置

1.config的原理:
config server 从远端git拉取一份配置信息—然后在本地存一份-----同时又对外提供服务 此时别的项目访问config服务端的时候去读取配置 你再修改配置的时候 应用的项目的是不会改变的 所以需要使用springcloud bus 利用消息队列来实现。

springcloud bus默认只支持rabbitmq和kafka。

2.config server 和需要用到config server服务的项目引入依赖

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-bus-amqp</artifactId>
            <version>2.0.1.BUILD-SNAPSHOT</version>
        </dependency>

3.config server项目的yml配置需要暴露 bus-refresh接口 需要post请求这个接口配置才会生效

management:
  endpoints:
    web:
      expose: "*"

4.在需要的项目中需要刷新的类上加入@RefreshScope 注解 这相当于是个范围

5.一般从yml中读取配置不用@velue 而使用一种前缀的方式
比如:
springcloud ---springcloud Bus自动更新配置
这里使用前缀而不使用@veluespringcloud ---springcloud Bus自动更新配置
使用该配置
springcloud ---springcloud Bus自动更新配置
6.在github中配置WeekHooks
首先需要把localhost映射成一个外网地址
这里使用 natapp.cn 工具
springcloud ---springcloud Bus自动更新配置
下载客户端
natapp -authtoken=0000000springcloud ---springcloud Bus自动更新配置
在github中配置Webhooks
springcloud ---springcloud Bus自动更新配置
springcloud ---springcloud Bus自动更新配置
springcloud ---springcloud Bus自动更新配置
这样就可以实现自动更新配置