Spring cloud configuration center

I. create Config configuration center project

1. Add dependency

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

2. To start the class, @ EnableConfigServer needs to be added

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;

/**
 * @author fusw
 */
@SpringBootApplication
@EnableConfigServer
public class ConfigCenterApplication {

    public static void main(String[] args) {
        SpringApplication.run(ConfigCenterApplication.class, args);
    }

}

3. Configuration file

eureka.instance.appname=base-iov-config
security.user.name=test
security.user.password=test
# GitLab configuration mode, must have. git suffix
# Configure the address of the default git warehouse
spring.cloud.config.server.git.uri=http://xxxx/config-repo.git
# Multiple relative addresses under git warehouse address can be configured and divided by ","
spring.cloud.config.server.git.search-paths=*
#Address stored after configuring the central clone warehouse configuration file
spring.cloud.config.server.git.basedir=/data/deploy/config-repo
spring.cloud.config.server.git.force-pull=true
# Account number of git warehouse
spring.cloud.config.server.git.username=test
# Password of git warehouse
spring.cloud.config.server.git.password=test



# Configure the address of other git warehouses spring.cloud.config.server.git.repos.x.uri, iot as an example
spring.cloud.config.server.git.repos.iot.uri=http://xxxx/iot/config-repo.git
spring.cloud.config.server.git.repos.iot.search-paths=*
spring.cloud.config.server.git.repos.iot.basedir=/data/deploy/config-repo
spring.cloud.config.server.git.repos.iot.force-pull=true
# Account number of git warehouse
spring.cloud.config.server.git.repos.iot.username=test
# Password of git warehouse
spring.cloud.config.server.git.repos.iot.password=test
#The prefix must be configured to distinguish it from the default warehouse
spring.cloud.config.server.git.repos.iot.pattern=Iot*

#Registry Center
eureka.client.serviceUrl.defaultZone=http://xxx/eureka/

II. git storage warehouse

Create a git warehouse to store the configuration of each project. You can create a folder according to the project in the project level directory (the name of each project folder can be started at will, and the Config configuration center only finds the configuration according to the configuration file name). Then each project folder stores the configuration files of different environments,
For example:
Iot-TestProject-dev.yml
Iot-TestProject-prd.yml
Iot-TestProject-test.yml

It is better not to place the default configuration similar to test.yml. If spring.profiles.active is not used to indicate the configuration file used in each project configuration file, the default configuration file will be loaded.

III. project configuration of each spring cloud access configuration center

In the bootstrap.properties configuration file under resource, the relevant configuration of the configuration center is as follows


# Use profile of default warehouse
spring.cloud.config.name=TestProject
# Using the configuration file of the iot factory Library
#spring.cloud.config.name=Iot-TestProject
#Which environment's configuration file to use, in combination with the above configuration, determines which configuration file to use: TestProject -test.yml
spring.cloud.config.profile=test


# git branch corresponding to the repository of configuration files
spring.cloud.config.label=master

spring.cloud.config.username=test
spring.cloud.config.password=test

# Enable Config service discovery support
spring.cloud.config.discovery.enabled=true
# Specify the name of the Server side, that is, the value of the Server side spring.application.name
spring.cloud.config.discovery.serviceId=base-iov-config

Tags: Java git Spring GitLab

Posted on Sun, 01 Dec 2019 00:55:19 -0800 by sois