SpringCloud 快速入門

2023-06-09 13:39 更新

此快速入門介紹了如何使用Spring Cloud Config服務(wù)器的服務(wù)器和客戶端。

首先,啟動服務(wù)器,如下所示:

$ cd spring-cloud-config-server
$ ../mvnw spring-boot:run

該服務(wù)器是Spring Boot應(yīng)用程序,因此,如果愿意,可以從IDE運(yùn)行它(主類是?ConfigServerApplication?)。

接下來嘗試一個客戶端,如下所示:

$ curl localhost:8888/foo/development
{"name":"foo","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"}}
]}

定位屬性源的默認(rèn)策略是克隆git存儲庫(位于?spring.cloud.config.server.git.uri?),并使用它來初始化小型?SpringApplication?。小型應(yīng)用程序的?Environment?用于枚舉屬性源并將其發(fā)布在JSON端點上。

HTTP服務(wù)具有以下形式的資源:

/{application}/{profile}[/{label}]
/{application}-{profile}.yml
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label}/{application}-{profile}.properties

?application?在?SpringApplication?中作為?spring.config.name?注入(在常規(guī)Spring Boot應(yīng)用中通常是?application?),?profile?是有效配置文件(或逗號分隔)屬性列表),而?label?是可選的git標(biāo)簽(默認(rèn)為?master?。)

Spring Cloud Config服務(wù)器從各種來源獲取遠(yuǎn)程客戶端的配置。以下示例從git存儲庫(必須提供)中獲取配置,如以下示例所示:

spring:
  cloud:
    config:
      server:
        git:
          uri: https://github.com/spring-cloud-samples/config-repo

其他來源包括任何與JDBC兼容的數(shù)據(jù)庫,Subversion,Hashicorp Vault,Credhub和本地文件系統(tǒng)。


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號