Spring Cloud Config用戶端使用

來源:互聯網
上載者:User

標籤:Spring Cloud   Spring Boot   

要在應用程式中使用這些功能,只需將其構建為依賴於spring-cloud-config-client的Spring引導應用程式(例如,查看配置用戶端或應用程式範例的測試案例)。添加依賴關係的最方便的方法是通過Spring Boot啟動器org.springframework.cloud:spring-cloud-starter-config。還有一個Maven使用者的父pom和BOM(spring-cloud-starter-parent)和用於Gradle和Spring CLI使用者的Spring IO版本管理屬性檔案。樣本Maven配置:

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.5.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Brixton.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

那麼你可以建立一個標準的Spring Boot應用程式,像這個簡單的HTTP伺服器:@SpringBootApplication@RestControllerpublic class Application { @RequestMapping("/") public String home() { return "Hello World!"; } public static void main(String[] args) { SpringApplication.run(Application.class, args); }}當它運行它將從連接埠8888上的預設本地設定管理員接收外部配置,如果它正在運行。要修改啟動行為,您可以使用bootstrap.properties(如application.properties)更改設定管理員的位置,但用於應用程式內容相關的引導階段),例如spring.cloud.config.uri:http://myconfigserver.com引導屬性將在/env端點中顯示為高優先順序屬性源,例如$ curl localhost:8080/env{ "profiles":[], "configService:https://github.com/spring-cloud-samples/config-repo/bar.properties":{"foo":"bar"}, "servletContextInitParams":{}, "systemProperties":{...}, ...}(名為“configService:<遠程存放庫的URL> / <檔案名稱>”的屬性源包含值為“bar”的屬性“foo”,是最高優先順序)。

Spring Cloud Config用戶端使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.