Build Spring Cloud Config

Source: Internet
Author: User
Tags list of attributes

A long time did not update, because not full-time research spring Cloud, so the update speed to see the intensity of the work is not much, every day can take out a little, if the update is too slow, and a small partner to see, please forgive me.

About Spring Cloud

Spring Cloud is a spring boot-based cloud application development tool for configuration management, service discovery, circuit breakers, intelligent routing, micro-agents, control buses, global locks, decision-making campaigns, Operations such as distributed sessions and cluster state management provide a simple way to develop.

Spring Cloud contains multiple sub-projects (for many different open source products involved in distributed systems), such as spring Cloud Config, Spring Cloud Netflix, Spring Cloud Cloudfoundry, Spring Cloud AWS, Spring Cloud Security, Spring Cloud Commons, Spring Cloud Zookeeper, Spring Cloud CLI, and more.

Spring Cloud Config Configuration management component

Before I knew spring cloud, I wanted to develop a configuration Management Server myself. Later I learned about Spring Cloud, contacted by Spring Cloud Config, and knew it as a configuration management, three ways to use Git, svn, and local file reads, combined with the git we're using is very good, it's natural to have configuration change logging, Roll back and suitable for use by operational engineer features. So decisively learning Spring Cloud Config is used as our configuration Management Server.

Its advantages: 1. Ability to log change log of configuration file

2. Ability to roll back quickly

3. Modify the configuration to notify the configuration of the use-side update configuration

4. If you are using built-in Tomcat, it is also possible to restart Tomcat

5. Easy and quick to build services

Below is a brief introduction to how to quickly build the configuration service:

The first is the startup class: plus @enableconfigserver annotations

@SpringBootApplication @enableconfigserverpublic class Cloudserverdemoapplication {public static void main (string[] args) {Springapplication.run (cloudserverdemoapplication.class, args);}}

Next is the introduction of POM files:

<?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> Your.groupid</groupid><artifactid>your.artifactid</artifactid><version>your.version </version><packaging>war</packaging><name>cloud-server-demo</name>< Description>demo Project for Spring boot</description><parent><groupid> org.springframework.boot</groupid><artifactid>spring-boot-starter-parent</artifactid>< Version>1.4.2.release</version><relativepath/> <!--lookup parent from repository--></ parent><properties><project.build.sourceencoding>utf-8</project.build.sourceencoding>< Project.reporting.outputencoding>utf-8</project.reporting.outputencoding><java.version>1.8</java.version><tomcat.version>8.5.5</ Tomcat.version></properties><dependencies><dependency><groupid> org.springframework.cloud</groupid><artifactid>spring-cloud-config-server</artifactid></ Dependency><dependency><groupid>org.springframework.boot</groupid><artifactid> Spring-boot-starter-web</artifactid></dependency><dependency><groupid> org.springframework.boot</groupid><artifactid>spring-boot-starter-tomcat</artifactid>< Scope>provided</scope></dependency><dependency><groupid>org.springframework.boot </groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope> </dependency><dependency> <groupId>org.springframework.boot</groupId> <ar Tifactid>spring-boot-starter-actuator</artifactid>        </dependency><dependency><groupId>org.springframework.boot</groupId><artifactId> spring-boot-starter-security</artifactid></dependency></dependencies>< dependencymanagement><dependencies><dependency><groupid>org.springframework.cloud</ Groupid><artifactid>spring-cloud-dependencies</artifactid><version>camden.sr2</version ><type>pom</type><scope>import</scope></dependency></dependencies></ dependencymanagement><build><plugins><plugin><groupid>org.springframework.boot</ groupid><artifactid>spring-boot-maven-plugin</artifactid></plugin></plugins></ Build></project>

Note the point: 1. If you want to use built-in tomcat boot, I am currently using a boot version of 1.4.2, its built-in Tomcat version is 8.5.6, 8.5.6 Tomcat has bugs, so change to 8.5.5.

2. If you want to invoke interface interfaces such as/refresh, you need to introduce spring-boot-starter-actuator dependencies. If you are reporting 404, make sure you are using a POST request.

Application.properties file

Describe the file name and the GIT branch corresponding request path in Git before the configuration

Composition of HTTP Service resources:/{APPLICATION}/{PROFILE}[/{LABEL}]/{APPLICATION}-{PROFILE}.YML/{LABEL}/{APPLICATION}-{PROFILE}.YML /{application}-{profile}.properties/{label}/{application}-{profile}.properties

Application is SpringApplication spring.config.name , (Generally speaking ' application ' is a regular spring boot application), profile is an active profile (or a comma-delimited list of attributes), The label is an optional git tag (default is "Master"). These values correspond to the configuration in the Configuration service consumption project, which is discussed later in this article.

Configure the most basic configuration service to specify GIT:

The first: (most basic, the simplest configuration service can be used after the designation)

Spring.cloud.config.server.git.uri

In a normal environment, configuration services provide services to multiple projects, and git is messy, and configuration services provide several configurations that differentiate individual projects:

The second type:

spring.cloud.config.server.git.uri:https://github.com/spring-cloud-samples/ config-repospring.cloud.config.server.git.repos.simple:https://github.com/simple/ config-repospring.cloud.config.server.git.repos.special.pattern:special*/dev*,*special*/dev* spring.cloud.config.server.git.repos.special.uri:https://github.com/special/ config-repospring.cloud.config.server.git.repos.local.pattern:local* Spring.cloud.config.server.git.repos.local.uri:file:/home/configsvc/config-repo

If {application}/{profile} no expression can be matched, the value corresponding to "Spring.cloud.config.server.git.uri" is used. In the above configuration, for the "simple" configuration library, the matching pattern is (and that is simple/* , whatever profile is, it only matches the application name called "simple" application system). The "local" library matches all application names starting with "local" for any application, regardless of the profiles (because there is no matching rule for profile, the /* suffix is automatically added to any matching expression), Special configuration library can only match profiles for dev*, we should understand, simple, special, local can be configured by themselves.

The third type:

spring.cloud.config.server.git.uri=https://github.com/vincent-ren/ Spring-boot-profile.gitspring.cloud.config.server.git.searchpaths={application}

Git address is my real used address (see), configure this item "Spring.cloud.config.server.git.searchpaths={application}", Configuring the client get configuration will go to the corresponding/{application} folder in the root directory of the Git repository according to the application name you have set up to find the configuration.

As a configuration service security issue is bound to be important.

The next article then goes on to configure the security of the service.

Build 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.