SpringCloud(12):SringCloud CONFIG-詳細構成のGitリポジトリ

詳細にGitのリポジトリ設定

  • gitのを使用していくつかの利点:
    • 監査バージョンを行うことができます。変更は履歴を表示することができ、修正などで人を参照してください。
    • より簡単そうに配布、ローカルファイルストレージと同様に、高可用性は、NFSまたはその他の分散ファイルシステムのない限り、別のものを得ることができません
    • 関係者はまた、gitのを使用することをお勧めします

参考住所:Finchley.SR2ドキュメント

基礎を使用してください

server:
  port: 8080
spring:
  cloud:
    config:
      server:
        git:
          uri: https://gitee.com/mmzs/microservice-spring-cloud-config-test
复制代码

通配符

server:
  port: 8080
spring:
  cloud:
    config:
      server:
        git:
		  # {application}表示根据应用名称寻找配置信息
          uri: https://gitee.com/mmzs/{application}
复制代码

パターンマッチングとリポジトリの複数

パターンマッチング

server:
  port: 8080
spring:
  cloud:
    config:
      server:
        git:
		  # 公用;即当simple和special都匹配不到时,就是用该仓库下的配置信息
          uri: https://gitee.com/mmzs/microservice-spring-cloud-config-test      
            simple: https://gitee.com/mmzs/simple
            special:
			  # 请求时使用:localhost:8080/mmzs/special-dev.properties
			  # 请求时使用:localhost:8080/mmzs/special-test.properties
              pattern: special*/dev*,special*/test*
              uri: https://gitee.com/mmzs/special
复制代码

検索パス

server:
  port: 8080
spring:
  cloud:
    config:
      server:
        git:
          uri: https://gitee.com/mmzs/microservice-spring-cloud-config-test      # 公用
          search-paths:
            - foo   # foo路径
            - bar   # bar路径
复制代码

cloneOnStartプロパティを使用します

server:
  port: 8080
spring:
  cloud:
    config:
      server:
        git:
          uri: https://gitee.com/mmzs/microservice-spring-cloud-config-test      # 公用
		  # 默认是false;即启动时不会连git仓库,把需要的资源都下载下来;而是首次请求的时候才下载
          clone-on-start: true  
          repos:
            simple: https://gitee.com/mmzs/simple
            special:
              pattern: special*/dev*,special*/test*
              uri: https://gitee.com/mmzs/special
              cloneOnStart: false   # 默认是false
复制代码

アカウントのパスワードを設定します

server:
  port: 8080
spring:
  cloud:
    config:
      server:
        git:
          uri: https://gitee.com/mmzs/microservice-spring-cloud-config-test
          username: xxx
          password: xxx
复制代码

検索パスでGitのプレースホルダ

(必要に応じて、及び{ラベル})は、以下に示すように、スプリングクラウド構成サーバはまた、例えば、プレースホルダ、{アプリケーション}と{プロファイル}の検索パスをサポートしています。

spring:
  cloud:
    config:
      server:
        git:
          uri: https://gitee.com/mmzs/microservice-spring-cloud-config-test
          searchPaths: '{application}'
复制代码

上記構成は、リポジトリ内の同じ名前のファイル検索ディレクトリ(最上層)を引き起こす、検索パス内のワイルドカードはまた、プレースホルダ(ディレクトリ検索が任意の一致を含む)と効果的です。

ます。https://juejin.im/post/5cfdcecf51882563ed6ad9ebで再現

おすすめ

転載: blog.csdn.net/weixin_33852020/article/details/93184019