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 Spring IO version Management properties file for Gradle and spring CLI users. Example MAVEN configuration:
the Pom.xml
<parent> <groupId>org.springframework.boot</groupId> <artifactid>spring-boot-starte r-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.s Pringframework.boot</groupid> <artifactId>spring-boot-maven-plugin</artifactId> </plugin></plugins></build> <!--repositories also needed for snapshots and milestones-
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) { SpringApplication.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) to change the location of the application.properties
configuration server, but for the boot phase of the application context, for example
spring.cloud.config.uri: http://myconfigserver.com
The Boot property /env
appears as a high-priority property source in the endpoint, such as
$ curl localhost:8080/env{ "profiles":[], "configService:https://github.com/spring-cloud-samples/config-repo/bar.properties":{"foo":"bar"}, "servletContextInitParams":{}, "systemProperties":{...}, ...}
(the property source named "configservice:< Remote Repository url>/< file name >" contains the property "foo" with the value "bar", which is the highest priority).
Attention |
The URL in the property source name is the Git repository, not the configuration server URL. |
Source Source
Spring Cloud Config Tutorial (v) client use