Config Server的Git仓库配置详解——模式匹配

一 介绍
模式匹配指的是带有通配符的{application}/{profile}名称的列表。如果{application}/{profile}不匹配任何模式,它将会使用spring.cloud.server.git.uri定义的URI。

其中application.yml内容如下
info:
  description: Spring Cloud Samples
  url: https://github.com/spring-cloud-samples
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
foo.properties的内容如下:
foo: from foo props
democonfigclient.message: hello spring io
三 Config Server的配置如下:
spring:
  cloud:
    config:
      server:
        git:
          uri: https://github.com/spring-cloud-samples/config-repo
          repos:
            simple: https://github.com/simple/config-repo
            special:
              pattern: special*/dev*,*special*/dev*
              uri: https://github.com/special/config-repo
            local:
              pattern: local*
              uri: file:/home/configsvc/config-repo
logging:
  level:
    org.springframework.cloud: DEBUG
    org.springframework.boot: DEBUG
该例中,对应simple仓库(该仓库其实在github上不存在),它只匹配所有配置文件中名为simple的应用程序。
local仓库匹配所有配置文件中以local开头的应用程序的名称。
四 测试
1 输入:http://localhost:8080/foo-default.yml,返回内容如下:
democonfigclient:
  message: hello spring io
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
foo: from foo props
info:
  description: Spring Cloud Samples
  url: https://github.com/spring-cloud-samples
从结果来看:匹配到了application.yml和foo.properties
2 输入 http://localhost:8080/special/dev,返回内容如下:
{
    "name": "special",
    "profiles": [
        "dev"
    ],
    "label": "master",
    "version": "a611374438e75aa1b9808908c57833480944e1a8",
    "state": null,
    "propertySources": [
        {
            "name": "https://github.com/spring-cloud-samples/config-repo/application.yml",
            "source": {
                "info.description": "Spring Cloud Samples",
                "info.url": "https://github.com/spring-cloud-samples",
                "eureka.client.serviceUrl.defaultZone": "http://localhost:8761/eureka/",
                "foo": "baz"
            }
        }
    ]
}
从结果来看:匹配到了application.yml,因为 https://github.com/special/config-repo这个仓库不存在。所以匹配到application.yml。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值