Enterprise Distribution Micro Service Cloud Springcloud springboot MyBatis (vi) Distributed Configuration Center (Spring Cloud Config)

Source: Internet
Author: User

First, Introduction

In distributed systems, because of the large number of services, in order to facilitate the unified management of service profiles, real-time updates, so the need for distributed configuration Center components. In spring cloud, there is a distributed Configuration center component, Spring Cloud Config, which enables configuration services to be placed in the memory of the configuration service (that is, local) and also in a remote Git repository. In Spring Cloud Config component, there are two roles, one is config server and the other is config client.

Second, build config Server

Create a Spring-boot project, named Config-server, whose pom.xml:

<?xml version= "1.0" encoding= "UTF-8"? ><project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "http ://www.w3.org/2001/XMLSchema-instance "xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > <modelversion>4.0.0 </modelVersion> <groupId>com.forezp</groupId> <artifactid>config-server</artifactid > <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>config-serv Er</name> <description>demo Project for Spring boot</description> <parent> <groupId>org.springframework.boot</groupId> &        Lt;artifactid>spring-boot-starter-parent</artifactid> <version>1.5.2.RELEASE</version> <relativePath/> <!--lookup parent from repository to </parent> <properties> <pro Ject.build.sourceencoding>utf-8</project.build.sourceencoding> <project.reporting.outputencoding >UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties&    Gt            <dependencies> <dependency> <groupId>org.springframework.cloud</groupId>            <artifactId>spring-cloud-config-server</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactid>spring-boot-starter-test&lt        ;/artifactid>    <scope>test</scope> </dependency> <dependency> &LT;GROUPID&GT;ORG.SPR Ingframework.cloud</groupid> <artifactId>spring-cloud-starter-eureka</artifactId> < /dependency> </dependencies> <dependencyManagement> <dependencies> <depend Ency> <groupId>org.springframework.cloud</groupId> <artifactid>spring-c Loud-dependencies</artifactid> <version>Camden.SR6</version> <type>p Om</type> <scope>Import</scope> </dependency> </dependencies> </dependencyManagement> &LT;BUILD&G        T                <plugins> <plugin> <groupId>org.springframework.boot</groupId>    <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins>            </build> <repositories> <repository> <id>spring-milestones</id> <name>spring milestones</name> <url>https://repo.spring.io/milestone</url><snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories></project>

At the entrance of the program application class plus the @enableconfigserver annotation opens the function of the configuration server, the code is as follows:

@SpringBootApplication @enableconfigserver  Public class configserverapplication {     publicstaticvoid  main (string[] args) {        Springapplication.run (configserverapplication. class , args);}    }

You need to configure the following in the program configuration file Application.properties file:

spring.application.name=config-serverserver.port=8888Spring.cloud.config.server.git.uri= HTTPS://github.com/forezp/springcloudconfig/spring.cloud.config.server.git.searchpaths=  Respospring.cloud.config.label=masterspring.cloud.config.server.git.username=your Usernamespring.cloud.config.server.git.password=your Password
    • Spring.cloud.config.server.git.uri: Configuring the Git repository address
    • Spring.cloud.config.server.git.searchPaths: Configuring the Warehouse Path
    • Spring.cloud.config.label: Configuring a branch of a warehouse
    • Spring.cloud.config.server.git.username: User name to access the GIT repository
    • Spring.cloud.config.server.git.password: Access the user password for the GIT repository

If the Git warehouse is a public warehouse, you can not fill in the user name and password, if the private warehouse needs to fill out, this example is open warehouse, rest assured that use.

There is a file in the remote repository https://github.com/forezp/SpringcloudConfig/. config-client-dev.properties file has a property:

foo = Foo Version 3

Startup program: Access Http://localhost:8888/foo/dev

{"Name": "foo", "Profiles": ["Dev"], "label": "Master","version": "792ffc77c03f4b138d28e89b576900ac5e01a44b "," state ":null," propertysources ": []}

The schema code is as follows:

Source source technical support for complete projects 2147775633

Enterprise Distribution Micro Service Cloud Springcloud springboot MyBatis (vi) Distributed Configuration Center (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.