Configure a remote git repository for Spring Cloud Config Server

Introduction

Although it is very convenient to create a git repository locally during the development process, in actual project applications, multiple project groups need to share configurations through a central server, so the Spring Cloud configuration center supports remote git repositories to enable decentralized projects. Groups can collaborate more easily.

basic environment

  • JDK 1.8
  • Maven 3.3.9
  • IntelliJ 2018.1
  • Git

Project source code

Gitee Code Cloud

Configure the remote git repository

First, I created a remote repository on gitee https://gitee.com/zxuqian/spring-cloud-config-remoteto store configuration files, and then we will access this repository through the configuration files. Then we migrate the previous local configuration files to this library. In order to test the effect, we modify web-client.ymlthe messagevalue of :此条消息来自于远程配置仓库

configure configserver

Now make some configuration changes in our previous configserver. First, in order to retain the previous configuration of the local warehouse, we application.ymlrenamed it to application-local.yml.

This -localone is one profileand its value is -later, i.e. local, we can bootstrap.ymlspecify which one to use in profile. For example, the configuration of the development phase and the production phase in the actual project is different, so there will be two or more configurations such as and application-development.yml.application-production.yml

Then create a new application-remote.ymlfile and add the following configuration content:

server:
  port: 8888
spring:
  cloud:
    config:
      server:
        git:
          uri: https://gitee.com/zxuqian/spring-cloud-config-remote
          username: 您的gitee用户名
          password: 您的gitee密码

Because it is a warehouse for self-use accounts, the account password is not provided, and it is changed to its own. uriThe address of the remote git repository is configured here .

Finally bootstrap.ymlenable our remoteprofile in:

spring:
  application:
    name: config-server
  profiles:
    active: remote

spring.profiles.activeThat is, our remoteProfile is specified, and the application-remote.ymlconfiguration file is used.

test

Use to spring-boot:runstart our config server, then access http://localhost:8888/web-client/default, and see the following results:

{"name":"web-client","profiles":["default"],"label":null,"version":"cbef7d379ef01d68810c3fdc2105b2226ea6c611","state":null,"propertySources":[{"name":"https://gitee.com/zxuqian/spring-cloud-config-remote/web-client.yml","source":{"message":"此条消息来自于远程配置仓库","management.endpoints.web.exposure.include":"*"}}]}

messageThe value is taken from the remote repository. Here web-client/defaultis 配置文件名/profile, because our web client project has no other Profile, the default value is the configuration defaultthat can be accessed only by writing it all in this way web-client.yml.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325990847&siteId=291194637