Git repository configuration in detail
- Several benefits of using git:
- Audit version can do: made changes can view the history, see who modified and so on;
- Distributed to do so more easily, like a local file storage, high availability can not, get another unless a nfs or other distributed file system
- The official also recommended to use git
Reference Address: Finchley.SR2 document
Use basis
server:
port: 8080
spring:
cloud:
config:
server:
git:
uri: https://gitee.com/mmzs/microservice-spring-cloud-config-test
复制代码
Tsuhaifu
server:
port: 8080
spring:
cloud:
config:
server:
git:
# {application}表示根据应用名称寻找配置信息
uri: https://gitee.com/mmzs/{application}
复制代码
Pattern matching and a plurality of repositories
Pattern Matching
server:
port: 8080
spring:
cloud:
config:
server:
git:
# 公用;即当simple和special都匹配不到时,就是用该仓库下的配置信息
uri: https://gitee.com/mmzs/microservice-spring-cloud-config-test
simple: https://gitee.com/mmzs/simple
special:
# 请求时使用:localhost:8080/mmzs/special-dev.properties
# 请求时使用:localhost:8080/mmzs/special-test.properties
pattern: special*/dev*,special*/test*
uri: https://gitee.com/mmzs/special
复制代码
Search Path
server:
port: 8080
spring:
cloud:
config:
server:
git:
uri: https://gitee.com/mmzs/microservice-spring-cloud-config-test # 公用
search-paths:
- foo # foo路径
- bar # bar路径
复制代码
Use cloneOnStart property
server:
port: 8080
spring:
cloud:
config:
server:
git:
uri: https://gitee.com/mmzs/microservice-spring-cloud-config-test # 公用
# 默认是false;即启动时不会连git仓库,把需要的资源都下载下来;而是首次请求的时候才下载
clone-on-start: true
repos:
simple: https://gitee.com/mmzs/simple
special:
pattern: special*/dev*,special*/test*
uri: https://gitee.com/mmzs/special
cloneOnStart: false # 默认是false
复制代码
Configuring account password
server:
port: 8080
spring:
cloud:
config:
server:
git:
uri: https://gitee.com/mmzs/microservice-spring-cloud-config-test
username: xxx
password: xxx
复制代码
Git placeholders in the search path
Spring Cloud Config Server also supports search path with placeholders, {application} and {profile} (and {label}, if desired), for example as shown in the following:
spring:
cloud:
config:
server:
git:
uri: https://gitee.com/mmzs/microservice-spring-cloud-config-test
searchPaths: '{application}'
复制代码
The above configuration causes the file search directory (and a top layer) of the same name in the repository, the wildcard in the search path is also effective with placeholders (directory search comprise any matches).
Reproduced in: https: //juejin.im/post/5cfdcecf51882563ed6ad9eb