Spring Cloud Config Tutorial (v) client use

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.