使用的本人的开放的git仓库,放在码云上:
https://gitee.com/Sunyelw/springcloud-config.git
先看一下总体的图,我觉得很清楚了。。
Config所有的访问路径:
../{application}/{profile}[/{label}]
../{application}-{profile}.yml
../{label}/{application}-{profile}.yml
../{application}-{profile}.properties
../{label}/{application}-{profile}.properties
访问../{application}/{profile}[/{label}]
举例:
访问URL:http://localhost:${server.port}/${search-paths}/${profile}/${label}
第一种,项目中使用的是:
server端的bootstrap.yml:
# 配置文件中心
spring:
application:
name: config-server
cloud:
config:
server:
git:
uri: https://gitee.com/Sunyelw/springcloud-config.git
profile: dev
label: master
failFast: true
client端的bootstrap.yml文件:
spring:
application:
name: config-client
cloud:
config:
name: config-client
uri: http://localhost:8860
label: master
profile: dev
failFast: true
这是通过../{label}/{application}-{profile}.yml
这种方式访问的。
第二种../{application}/{profile}[/{label}]
server端的bootstrap.yml:
spring:
application:
name: config-server
cloud:
config:
server:
git:
uri: https://gitee.com/Sunyelw/springcloud-config.git
search-paths: springcloud-config
profile: dev
label: master
failFast: true
PS: 注意上面的search-paths: springcloud-config
client端的bootstrap.yml文件:
spring:
application:
name: config-client
cloud:
config:
name: springcloud-config
uri: http://localhost:8860
label: master
profile: dev
failFast: true
这里的name
需要跟上面的search-paths
一致,否则看到报错信息也明白了。
说几点注意点:
(1)yml文件与properties文件是一样的,只是配置方式不同,看个人喜好;
(2)千万注意你的配置名称,千万别少或多几级
,我少了两级卡了两天,难受;
(3)bootstrap的加载在应用启动前,application在启动时加载,也就是说你如果把git配置放在application中是会找不到仓库中的值的;
(4)config server端的application文件好像不能直接使用git库中的值,反正我是没成功,而且项目中也是一个配置中心,所有项目都要配置这个配置中心去获取配置;我猜也是读取不到,不然没必要多次一举。如果有不同的意见请留言评论告知一下,谢谢。
另外,这个项目我集成在github上了https://github.com/Sunyelw/cloud.git