Spring Cloud Config 之 Git Backend
Reference:
spring-cloud-config详细讲述了使用文件系统或Git做backend时的基本使用方法,以及在复杂使用场景下的配置。
Spring Profiles 讲述了profile在configuration中的作用及使用方法。
Spring Cloud Configuration的使用包括server和client。
Configuration Server作为配置信息的统一的、集中的数据源。Configuration Client从server端获取数据。
Server端的配置:
spring.cloud.config.server.git.uri=/Users/dahui/GitHub/config-repo
server.port=8888
Client端的配置
spring.application.name=reservation-service
spring.profiles.active=profile1,profile3
SpringConfigClient_GitBackend.png
spring.cloud.config.uri=http://localhost:8888
下图仅仅演示了最简单的application name、profile、label的使用。
实际场景中的图中profile一般设置为dev、qa、production等。label用于对application+profile提供标识版本的能力。
Config Client端配置说明:
在Confige Server使用的配置文件中的配置优先级高于Confige Client本地的配置。
比如,confige client本地的bootstrap.properties中定义了server.port=8866,在git文件中定义server.port=8000,那么config client实际使用的是8000. (即使在application.properties文件中定义,也无效。)在config client项目中添加Actuator库,通过浏览器访问http://localhost:8888/mappings,就可以看到Actuator提供的REST接口。其中的POST /refresh可以用于当config server的配置信息发生变化时,让client去pull一下最新的值。
可以同通过 curl -d {} http://localhost:8000/refresh 获取更新。