SpringCloud Config(一) 配置方式的几种搭配

使用的本人的开放的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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值