Start Spring Cloud Config

Source: Internet
Author: User

What is Spring Cloud Config

The Spring Cloud Config project provides a configuration management solution for distributed systems. It contains two parts of the client and server.

Spring Cloud Config Sever manages the external configuration of Git or SVN, centrally configured to all clients.

The Spring Cloud Config client gets the configuration based on the spring framework Environment and PropertySource from Spring Cloud Config sever.

All to start with spring Cloud Config, be sure to first understand,,, and Spring Boot Environment PropertySource Profile Other Technologies

The default git-based configuration is available on the Spring Cloud Web site, and the following example is based on SVN, which is replaced with the SVN address www.xxx.com , which is modified separately.

@EnableConfigServer

To build spring Cloud Config Server, you need only one@EnableConfigServer

@Configuration@EnableAutoConfiguration@EnableConfigServerpublicclass App {    publicstaticvoidmain(String... args) {        SpringApplication.run(App.class, args).getEnvironment();    }}

Under to resource, add application.yml , plus configure

server:  8888spring:  profiles:    active: subversion  cloud:    config:      server:        svn:          uri: https://www.xxx.com/svn/demo/demo-config-repo

Add Pom.xml configuration, need to bring into spring boot, Spring cloud and SVN jar

<!--Spring Cloud parent version-->    <parent>        <groupId>Org.springframework.cloud</groupId>        <artifactid>Spring-cloud-starter-parent</artifactid>        <version>Angel.sr3</version>    </Parent>    <properties>        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>        <start-class>Com.xxx.App</start-class>        <java.version>1.8</java.version>    </Properties>    <dependencies>        <!--Spring Cloud config server-->        <dependency>            <groupId>Org.springframework.cloud</groupId>            <artifactid>Spring-cloud-config-server</artifactid>        </Dependency>        <!--config server need read svn-->        <dependency>            <groupId>Org.tmatesoft.svnkit</groupId>            <artifactid>Svnkit</artifactid>            <version>1.8.10</version>        </Dependency>        <!--spring boot test-->        <dependency>            <groupId>Org.springframework.boot</groupId>            <artifactid>Spring-boot-starter-test</artifactid>            <scope>Test</Scope>        </Dependency>    </dependencies>    <build>        <plugins>            <!--mvn spring-boot:run command --            <plugin>                <groupId>Org.springframework.boot</groupId>                <artifactid>Spring-boot-maven-plugin</artifactid>            </plugin>        </plugins>    </Build>

https://www.xxx.com/svn/demo/demo-config-reposubmit a file below, such asdemo-development.properties

Run App.class, Access http://localhost:8888/{application}/{profile}/{label} , for example: http://localhost:8888/dmeo/development/trunk
It worked.

{    name: "demo",    profiles: [        "developement"    ],    label: "trunk",    propertySources: [        {            name: "https://www.xxx.com/svn/demo/demo-config-repo/trunk/demo.properties",            source: {                demo.env: "default"            }        }    ]}
    • {Application} matches client's "Spring.application.name"

    • {Profile} matches client's "Spring.active.profiles"

    • {Label} if it is svn matching trunk/branchs, and so on.

Try providing the properties of SVN, accessing, discovering configuration information and changing it.

Spring Cloud Config Client

Client, a new spring boot project is still being created. Add to spring-cloud-config-client Package

<dependency>    <groupId>org.springframework.cloud</groupId>    <artifactId>spring-cloud-config-client</artifactId></dependency>

Add bootstrap.yml to the resources below. Join the configuration

spring:  cloud:    config:      name: loupan      profile: development      label: trunk      uri: http://localhost:8888

Here http://localhost:8888 is the application of Spring Cloud Config Server, which is just launched.

2015-08-27  18:01  :03  .751  info  11520 --- [main]  b  .c  : located   Property  source : compositepropertysource  [name= ' Configservice ', Propertysources=[mappropertysource [name= ' https://www.xxx.com/ Svn/demo/demo-config-repo/trunk/demo-developement.properties '] , MapPropertySource  [name= ' https://www.xxx.com/svn/demo/demo-config-repo/trunk/ Demo.properties '] ] 

The startup message found such a log, it succeeded. It will automatically load the project inside, you can use the spring automatic configuration conveniently using the external configuration.
For example, application.properties it is used directly inside

spring.profiles.active = ${demo.env}

Or

@Configurationpublic class DemoConfig {    @Value("${demo.env}")    public String env;   ...

In addition, he offers a number of ways to meet demand. For example, after modifying the configuration, you can

$ curl -XPOSThttp://localhost:8080/refresh

To refresh the configuration.

$ curl -XPOSThttp://localhost:8080/restart

。。。

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Start Spring Cloud Config

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.