spring cloud 配置中心是一个管理应用配置的工具组件
用到了gitlab 保存配置文件
配置中心本身是一个spring boot 服务
在对应目录中 配置 好 gitlab 上保存配置的地址
使用服务名/profire/版本 来获取 配置
例如 :
启动命令:
--spring.profile.level=DEBUG
--eureka.client.register-with-eureka=true
--spring.cloud.config.enabled=true
--spring.config.location=http://master.dev-cluster.XXXX.org/bootstrap.main.yml,http://master.dev-cluster.XXXX.org/bootstrap.back.yml
--spring.profiles.active=dev
启动之后 服务先获取配置中心地址
:http://master.dev-cluster.XXXX.org/bootstrap.main
读取配置:
spring:
profiles:
active: dev
cloud:
config:
enabled: true
discovery:
enabled: true
service-id: facility-config
username: user
password: password
label: 3.1
eureka:
instance:
prefer-ip-address: true
client:
service-url:
defaultZone: http://username:password@eureka.XXXX.org:30000/eureka
载获取配置项:
Fetching config from server at: http://10.200.133.49:8762/
2018-12-06 18:08:32.743 INFO 35040 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Located environment: name=dubbo-service-beego, profiles=[dev], label=3.1, version=93505ed4a6f55b93f7fecb1d25d9fe11c137803e, state=null
2018-12-06 18:08:32.744 INFO 35040 --- [ main] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource [name='configService', propertySources=[MapPropertySource [name='configClient'], MapPropertySource [name='https://rep.360taihe.com/fd/fd-server-config.git/application-dev.properties'], MapPropertySource [name='https://rep.360taihe.com/fd/fd-server-config.git/application-dev.yml'], MapPropertySource [name='https://rep.360taihe.com/fd/fd-server-config.git/application.properties']]]
2018-12-06 18:08:32.816 INFO 35040 --- [ main] com.tairanchina.beego.BeegoServer : The following profiles are active: dev
配置中心组装真实配置的URL:http://10.200.133.49:8762/dubbo-service-beego/dev/3.1
从而获取到生效的配置
注意
配置中心服务的配置并不是从gitlab 实时获取的,
一般从本地的tmp 缓存目录下获取
在更新配置的时候需要清除对应缓存
重启应用服务才可生效
缓存目录
[root@host-10-200-133-49 config-repo-2268156099382031184]# pwd
/tmp/config-repo-2268156099382031184
[root@host-10-200-133-49 config-repo-2268156099382031184]#