配置文件的spring云配置模式匹配

配置文件的spring云配置模式匹配,spring,spring-boot,cloud,config,spring-cloud,Spring,Spring Boot,Cloud,Config,Spring Cloud,我试图基于应用程序的不同配置文件实现SpringCloud配置的模式匹配功能。根据中的文档,可以根据配置文件匹配存储库。下面是我的配置服务器application.yml server: port: 8888 spring: cloud: config: server: git: uri: ssh://xxxx@github/sample/cloud-config-properties.git repos:

我试图基于应用程序的不同配置文件实现SpringCloud配置的模式匹配功能。根据中的文档,可以根据配置文件匹配存储库。下面是我的配置服务器application.yml

server:
  port: 8888
spring:
  cloud:
    config:
      server:
        git:
          uri: ssh://xxxx@github/sample/cloud-config-properties.git
          repos:
            development:
             pattern:
               -*/development    
               -*/staging 
             uri: ssh://git@xxxgithub.com/development.git
            test:
             pattern: 
               -*/test
               -*/perf
             uri: ${HOME}/Documents/cloud-config-sample-test
我有一个配置客户端应用程序“user”,并且有user.properties、user-development.properties、user-test.properties

根据文档-无论应用程序名称如何,如果模式匹配*/development i,即localhost:8888/user/development或localhost:8888/demo/development,则我的配置服务器应匹配配置文件模式并获取适当的属性。 前任: 我应该从中获取demo-development.propertiesssh://git@xxxgithub.com/development.git

但在我的应用程序中,默认uri用于所有配置文件,即我的属性文件demo.properties从 uri:ssh://xxxx@github/sample/cloud-config-properties.git

有什么建议吗

编辑: pom.xml


org.springframework.cloud
SpringCloudStarter父级
Brixton.M5
org.springframework.cloud
spring云配置服务器
org.springframework.boot
弹簧起动试验
测试
org.springframework.cloud
spring云配置监视器
org.springframework.cloud
springcloudstarter总线amqp
org.springframework.boot
弹簧启动安全
org.springframework.boot
springbootmaven插件
春季快照
春季快照
http://repo.spring.io/libs-snapshot-local
真的
春季快照连续
春季快照连续
http://repo.spring.io/libs-snapshot-continuous-local
真的
春季里程碑
春季里程碑
http://repo.spring.io/libs-milestone-local
假的
春假
春假
http://repo.spring.io/libs-release-local
假的
春季快照
春季快照
http://repo.spring.io/libs-snapshot-local
真的
春季里程碑
春季里程碑
http://repo.spring.io/libs-milestone-local
假的

在对PatternMatching源代码进行了一些调试之后,以下是我解决问题的方法:您可以选择以下两种方法之一

application.yml
server:
  port: 8888
spring:
  cloud:
    config:
      server:
        git:
          uri: ssh://xxxx@github/sample/cloud-config-properties.git
          repos:
           development:
            pattern: '*/development' ## give in quotes
            uri: ssh://git@xxxgithub.com/development.git

模式:*/development.Error在yml文件上-应为字母或数字字符,但找到了,但找到了/

配置文件模式git repo未被识别的原因是:尽管spring允许对yml文件中以“-”开头的模式使用多个数组值,但模式匹配器将“-”作为要匹配的字符串。i、 e它正在寻找一种模式
'-*/development'
,而不是
'*/development'

   repos:
    development:
     pattern:
      -*/development    
      -*/staging 
我观察到的另一个问题是,如果我不得不将模式数组称为
'-*/development'
-请注意连字符后的空格(这意味着它可以作为数组保存多个值),并以带有错误的“*/development”开头,则yml文件会出现编译错误:应为字母或数字字符,但是找到了,但是找到了/

 repos:
        development:
         pattern:
          - */development    
          - */staging 

您使用的是什么版本?Brixton.M5 pom.xml:org.springframework.cloud-spring-cloud-starter父级Brixton.M5是的,很抱歉我之前没有看到。这是一个YML问题,以
*
开头的字符串需要被
'
包围。
   repos:
    development:
     pattern:
      -*/development    
      -*/staging 
 repos:
        development:
         pattern:
          - */development    
          - */staging