Git
1. 修改 application.yml
spring:
application:
name: config-server
profiles:
active: git
cloud:
config:
server:
git:
uri:
https://gitee.com/zhang993632987/config.git
search-paths: '{application}'
default-label: master
refresh-rate: 0
deleteUntrackedBranches: true
basedir: file:///F:/tmp
spring.profiles.active=git
使用 git 作为后端,存储配置信息。
spring.cloud.config.server.git.search-locations={application}
指定搜索路径,可以使用占位符 {application}、{profile} 和 {label},其中:
application 表示客户端应用的名称(spring.application.name)
profile 为客户端的环境(spring.profiles.active)
label 指示分支版本(spring.cloud.config.label)
spring.cloud.config.server.git.uri=https://gitee.com/zhang993632987/config
仓库地址
spring.cloud.config.server.git.default-label=master
默认分支(branch)
spring.cloud.config.server.git.refresh-rate=0
刷新本地配置的频率,单位为秒。“0” 代表每次客户端请求配置信息时,均会请求 git 仓库。
spring.cloud.config.server.git.deleteUntrackedBranches=true
在 Config Server 启动时,会将指定的 git 仓库克隆到本地,本地仓库会一直存在直到 Config Server 重启。deleteUntrackedBranches 表示 Config Server 会强制删除 untracked 的分支。
spring.cloud.config.server.git.basedir=file:///F:/tmp
远程仓库克隆下来后的存储地址,默认存在临时文件夹中,可以指定也可以不指定。
2. git 仓库

3. 认证
对于私有的远程仓库,需要添加认证信息才能连接上,此时可以采用“私人令牌”的方式进行用户认证。使用“私人令牌”可以控制令牌拥有的权限,防止账户密码泄露:
spring:
cloud:
config:
server:
git:
uri:
https://gitee.com/zhang993632987/config
default-label: master
refresh-rate: 0
search-paths: '{application}'
deleteUntrackedBranches: true
username: '17336538193'
password: 'bea83aa8df4a3355d06ab2837c97fa4c'
Last updated