To use these features in your application, simply build them into a spring-guided application that relies on spring-cloud-config-client (for example, to view test cases for configuring a client or sample application). The most convenient way to add dependencies is through the Spring boot launcher org.springframework.cloud:spring-cloud-starter-config. There is also a MAVEN user's parent pom and BOM (spring-cloud-starter-parent) and a spring IO version management properties file for Gradle and spring CLI users. Example MAVEN configuration:
<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>
Then you can create a standard spring boot application like this simple HTTP server: @SpringBootApplication @restcontrollerpublic class Application {@ Requestmapping ("/") Public String Home () {return ' Hello world! ';} public static void Main (string[] args) {Springapplica Tion.run (Application.class, args); }} When it runs it will receive the external configuration from the default local configuration server on port 8888 if it is running. To modify the startup behavior, You can use Bootstrap.properties (such as application.properties) to change the location of the configuration server, but for the boot phase of the application context, such as spring.cloud.config.uri:http:/ The/myconfigserver.com boot property is displayed as a high-priority property source in the/env endpoint, such as Curl localhost:8080/env{"profiles": [], "configservice:https:// Github.com/spring-cloud-samples/config-repo/bar.properties ": {" foo ":" Bar "}," Servletcontextinitparams ": {}," Systemproperties ": {...}, ...} (named "Configservice: <远程存储库的url> <远程存储库的url> / <文件名> "property source contains the property" foo "with the value" bar ", which is the highest priority).
The Spring Cloud Config client uses