2016-04-07 23 views
1

私は、アプリケーションのさまざまなプロファイルに基づいて、Springクラウド設定のパターンマッチング機能を実装しようとしています。 http://cloud.spring.io/spring-cloud-config/spring-cloud-config.html#_environment_repositoryのドキュメントに基づいて、プロファイルに基づいてリポジトリを照合することは可能です。以下は、私が設定クライアントアプリケーション "ユーザー" を持っているとuser.properties、user-development.propertiesを持って、私のconfigサーバapplication.ymlプロファイル用のスプリングクラウド設定パターンの一致

server: 
    port: 8888 
spring: 
    cloud: 
    config: 
     server: 
     git: 
      uri: ssh://[email protected]/sample/cloud-config-properties.git 
      repos: 
      development: 
      pattern: 
       -*/development  
       -*/staging 
      uri: ssh://[email protected]/development.git 
      test: 
      pattern: 
       -*/test 
       -*/perf 
      uri: ${HOME}/Documents/cloud-config-sample-test 

ある文書に基づいて

をuser-test.properties - アプリケーション名に関係なく、パターンが*/development i、localhost:8888/user/developmentまたはlocalhost:8888/demo/developmentと一致する場合、my config serverはプロファイルパターンと一致し、適切なプロパティを取得する必要があります。 例:http://localhost:8888/demo/development 私はSSHからdemo-development.propertiesを取得する必要があります://[email protected]/development.git

しかし、私のアプリケーションでは、デフォルトのURIは、すべてのプロファイルに使用されますが、私のプロパティファイルのデモ、すなわち.propertiesは から返されます。uri:ssh://[email protected]/sample/cloud-config-properties.git

これについての指針はありますか?

EDIT:あなたは2つの方法のいずれかを選択できます。ここでのパターンマッチングのソースコードにいくつかのデバッグ後 のpom.xml

<parent> 
     <groupId>org.springframework.cloud</groupId> 
     <artifactId>spring-cloud-starter-parent</artifactId> 
     <version>Brixton.M5</version> 
     <relativePath /> 
    </parent> 
    <dependencies> 
     <dependency> 
      <groupId>org.springframework.cloud</groupId> 
      <artifactId>spring-cloud-config-server</artifactId> 
     </dependency> 
<dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-test</artifactId> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.cloud</groupId> 
      <artifactId>spring-cloud-config-monitor</artifactId> 
     </dependency> 
<dependency> 
      <groupId>org.springframework.cloud</groupId> 
      <artifactId>spring-cloud-starter-bus-amqp</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-security</artifactId> 
     </dependency> 
    </dependencies> 
    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.springframework.boot</groupId> 
       <artifactId>spring-boot-maven-plugin</artifactId> 
      </plugin> 
     </plugins> 
    </build> 
<repositories> 
     <repository> 
      <id>spring-snapshots</id> 
      <name>Spring Snapshots</name> 
      <url>http://repo.spring.io/libs-snapshot-local</url> 
      <snapshots> 
       <enabled>true</enabled> 
      </snapshots> 
     </repository> 
     <repository> 
      <id>spring-snapshots-continuous</id> 
      <name>Spring Snapshots Continuous</name> 
      <url>http://repo.spring.io/libs-snapshot-continuous-local</url> 
      <snapshots> 
       <enabled>true</enabled> 
      </snapshots> 
     </repository> 
     <repository> 
      <id>spring-milestones</id> 
      <name>Spring Milestones</name> 
      <url>http://repo.spring.io/libs-milestone-local</url> 
      <snapshots> 
       <enabled>false</enabled> 
      </snapshots> 
     </repository> 
     <repository> 
      <id>spring-releases</id> 
      <name>Spring Releases</name> 
      <url>http://repo.spring.io/libs-release-local</url> 
      <snapshots> 
       <enabled>false</enabled> 
      </snapshots> 
     </repository> 
    </repositories> 
    <pluginRepositories> 
     <pluginRepository> 
      <id>spring-snapshots</id> 
      <name>Spring Snapshots</name> 
      <url>http://repo.spring.io/libs-snapshot-local</url> 
      <snapshots> 
       <enabled>true</enabled> 
      </snapshots> 
     </pluginRepository> 
     <pluginRepository> 
      <id>spring-milestones</id> 
      <name>Spring Milestones</name> 
      <url>http://repo.spring.io/libs-milestone-local</url> 
      <snapshots> 
       <enabled>false</enabled> 
      </snapshots> 
     </pluginRepository> 
    </pluginRepositories> 
+0

あなたはどのバージョンを使用していますか? – spencergibb

+0

Brixton.M5 のpom.xml: \t org.springframework.cloud \t ばねクラウドスタータ親 \t Brixton.M5 \t \t

答えて

1

が、私は問題を解決する方法です。

application.yml 
server: 
    port: 8888 
spring: 
    cloud: 
    config: 
     server: 
     git: 
      uri: ssh://[email protected]/sample/cloud-config-properties.git 
      repos: 
      development: 
      pattern: '*/development' ## give in quotes 
      uri: ssh://[email protected]/development.git 

OR

development: 
    pattern: xx*/development,*/development ##since it is not allowed to have a value starting with a wildcard('*')after pattern I first gave a generic matching but the second value is */development. Since pattern takes multiple values, the second pattern will match with the profile 
    uri: ssh://[email protected]/development.git 

パターン:*/development.Error YMLの[ファイル] - 上には、アルファベットや数字を期待したが、見つかりましたが、/を見つけました。

springはymlファイルの ' - 'で始まるパターンの複数の配列値を許容しますが、パターンマッチャーはマッチする文字列として ' - 'を取っていたため、プロファイルパターンgit repoが特定されなかったためです。すなわち、'*/development'の代わりにパターン'-*/development'を探しています。

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

私は'- */development'ようなパターン配列を言及していた場合、私は、私はYMLファイルにコンパイルエラーを取得した観測もう一つの問題 - それはのように複数の値を保持できることを示すために意図されるハイフンの後のノートスペース(配列)とエラーで「* /開発」で開始:アルファベットや数字を期待したが、見つかりましたが、見つから/

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

ええ、すみませんでした。それはYMLの問題です。 '*'で始まる文字列は '' 'で囲む必要があります。 – spencergibb

関連する問題