spring cloud微服務分散式雲架構- Config 快速開始

使用者6866800318發表於2019-03-20

啟動伺服器:

$ cd spring-cloud-config-server
$ ../mvnw spring-boot:run
複製程式碼

該伺服器是一個Spring Boot應用程式,所以您可以從IDE執行它,而不是喜歡(主類是ConfigServerApplication)。然後嘗試一個客戶端:Spring Cloud大型企業分散式微服務雲架構原始碼請加一七九一七四三三八零

$ curl localhost:8888/foo/development
{"name":"development","label":"master","propertySources":[
  {"name":"https://github.com/scratches/config-repo/foo-development.properties","source":{"bar":"spam"}},
  {"name":"https://github.com/scratches/config-repo/foo.properties","source":{"foo":"bar"}}
]}
複製程式碼

定位資源的預設策略是克隆一個git倉庫(在spring.cloud.config.server.git.uri),並使用它來初始化一個迷你SpringApplication。小應用程式的Environment用於列舉屬性源並通過JSON端點發布。

HTTP服務具有以下格式的資源:

/{application}/{profile}[/{label}]
/{application}-{profile}.yml
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label}/{application}-{profile}.properties
複製程式碼

其中“應用程式”作為SpringApplication中的spring.config.name注入(即常規的Spring Boot應用程式中通常是“應用程式”),“配置檔案”是活動配置檔案(或逗號分隔列表的屬性),“label”是可選的git標籤(預設為“master”)。

Spring Cloud Config伺服器從git儲存庫(必須提供)為遠端客戶端提供配置:

spring:
  cloud:
    config:
      server:
        git:
          uri: https://github.com/spring-cloud-samples/config-repo
複製程式碼

相關文章