1.、版本要求
- springboot 版本
2.0.6.RELEASE
- springcloud版本
Finchley.SR2
/{name}-{profiles}.yml
/{label}/{name}-{profiles}.yml
name : 文件名,一般以服务名来命名
profiles : 一般作为环境标识
lable : 分支(branch),指定访问某分支下的配置文件
2.引入springcloud-bus依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
3.service-config配置读取配置文件地址
- uri: 地址
- basedir:指定存放路径
spring:
application:
name: config
cloud:
config:
server:
git:
uri: https://gitee.com/matea/config-repo
username: XXXXXX
password: XXXXXX
basedir: E:\WorkSpace\IDEA\config-git
4.暴露bus-refresh接口,可以出发刷新配置文件
management:
endpoints:
web:
expose: "*"
#include: bus-refresh
5.添加注解@RefreshScope
- 涉及到需要刷新的地方添加注解 @RefreshScope
@RestController
@RequestMapping("/env")
@RefreshScope
public class EnvController {
@Value("${env}")
private String env;
@GetMapping("/print")
public String print(){
return env;
}
}
6.测试触发bus-refresh更新配置文件
http://127.0.0.1:9001/actuator/bus-refresh
7.使用WebHooks设置自动刷新
- 码云在管理里面 但不行
- 使用github Settings
http://fvhy73.natappfree.cc/monitor
application/json
注:github中不使用/actuator/bus-refresh