# 1.引入依赖
org.springframework.cloud
spring-cloud-config-server
# 2.开启统一配置中心服务
@SpringBootApplication
@EnableConfigServer
public class Configserver7878Application {
public static void main(String[] args) {
SpringApplication.run(Configserver7878Application.class, args);
}
}
# 3.修改配置文件
server.port=7878
spring.application.name=configserver
spring.cloud.consul.host=localhost
spring.cloud.consul.port=8500
# 4.直接启动服务报错
- 没有指定远程仓库的相关配置
# 5.创建远程仓库
- github创建一个仓库
# 6.复制仓库地址
- https://github.com/java/configservers.git
# 7.在统一配置中心服务中修改配置文件指向远程仓库地址
spring.cloud.config.server.git.uri=https://github.com/java/configservers.git 指定仓库的url
spring.cloud.config.server.git.default-label=master 指定访问的分支
#spring.cloud.config.server.git.username= 私有仓库访问用户名
#spring.cloud.config.server.git.password= 私有仓库访问密码
# 8.再次启动统一配置中心
# 9.拉取远端配置 [三种方式][]
- 1. http://localhost:7878/test-xxxx.properties
- 2. http://localhost:7878/test-xxxx.json
- 3. http://localhost:7878/test-xxxx.yml
# 10.拉取远端配置规则
- label/name-profiles.yml|properties|json
`label 代表去那个分支获取 默认使用master分支
`name 代表读取那个具体的配置文件文件名称
`profile 代表读取配置文件环境
# 11.查看拉取配置详细信息
- http://localhost:7878/client/dev [client:代表远端配置名称][dev:代表远程配置的环境]
# 12.指定分支和本地仓库位置
spring.cloud.config.server.git.basedir=/localresp #一定要是一个空目录,在首次会将该目录清空
spring.cloud.config.server.git.default-label=master