Spring-cloud-config (configuration Center ),
Preface
In a distributed system, due to the large number of services, in order to facilitate unified management of service configuration files and real-time updates, the distributed configuration center component: spring-cloud-config, it supports configuring services in the memory (local) of the configuration service and remote Git repository.
This section describes how to use the Git repository as the configuration source.
Open Source Address: https://github.com/bigbeef
Create a configuration project
Create a project in github to save the configuration files of all our projects. The project is my project structure.
Configure Project address: https://github.com/bigbeef/cppba-config
Eureka-server.properties
eureka.client.register-with-eureka=falseeureka.client.fetch-registry=falsespring.application.name=eureka-serverserver.port=18761eureka.instance.hostname=peer1eureka.client.serviceUrl.defaultZone=http://peer1:18761/eureka/
Create a spring-cloud-config-server project
Project Structure
Pom. xml Core code
<dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId> </dependency></dependencies>
SpringCloudConfigServerApplication. java
package com.cppba;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.config.server.EnableConfigServer;@SpringBootApplication@EnableConfigServerpublic class SpringCloudConfigServerApplication { public static void main(String[] args) { SpringApplication.run(SpringCloudConfigServerApplication.class, args); }}
Application. properties
Modify the configuration according to your actual git project.
server.port=8888spring.application.name=config-serverspring.cloud.config.server.git.uri=https://github.com/bigbeef/cppba-configspring.cloud.config.label=master# spring.cloud.config.server.git.username=# spring.cloud.config.server.git.password=spring.cloud.config.server.git.searchPaths=\ cppba-spring-cloud/*,\ cppba-spring-cloud/eureka-client/*
Spring. cloud. config. server. git. uri: configure the git repository address.
Spring. cloud. config. server. git. searchPaths: configure the repository path, separated by commas
Spring. cloud. config. label: configure the branch of the Repository
Spring. cloud. config. server. git. username: the username used to access the git repository.
Spring. cloud. config. server. git. password: the user password used to access the git repository.
Start the project
Access address: http: // 127.0.0.1: 8888
The ing between the http request address and the resource file is as follows:
/{Application}/{profile} [/{label}]
/{Application}-{profile}. yml
/{Label}/{application}-{profile}. yml
/{Application}-{profile}. properties
/{Label}/{application}-{profile}. properties
Based on our own configuration, we can access: http: // 127.0.0.1: 8888/eureka-server/default/master
Application-> eureka-server (application name)
Profile-> default (the enabled configuration is usually a suffix, which is explained below)
Label-> master (Branch)
The access result is:
Profile is important. It can be understood as the configuration files to read. If I have more than one configuration file, there may be:
Eureka-server.properties (this is a common configuration file, which is loaded by default ),
Eureka-server-mysql.properties,
Eureka-server-oracle.properties,
Eureka-server-jpa.properties,
Eureka-server-mysql.properties ......
We may selectively load some of the properties configuration files, so we can write: http: // 127.0.0.1: 8888/eureka-server/default, mysql, jpa/master
At this point, our spring-cloud-config-server is simple. I will teach you how to read configurations in the project in the following sections.
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.