Get the App
SLTechnology News&Howtos  ›  Servers  › 

Configure a remote git repository for Spring Cloud Config Server

Shulou Source: shulou.com Published: 2022-06-03 00:13:02 10月03日 Update

Brief introduction

Although it is very convenient to create a local git repository in the development process, in practical project applications, multiple project teams need to share configuration through a central server, so the Spring Cloud configuration center supports remote git repositories to make it easier for dispersed project teams to collaborate.

Basic environment JDK 1.8Maven 3.3.9IntelliJ 2018.1Git project source code

Gitee Code Cloud

Configure a remote git repository

First I created a remote repository https://gitee.com/zxuqian/spring-cloud-config-remote on gitee to hold configuration files, and then we will access this repository through configuration files. Then we migrate the previous local configuration files to this library. To test the effect, we modify the value of web-client.yml 's message to: this message is from the remote configuration repository

Configure configserver

Now make some configuration changes in our previous configserver. First of all, to preserve the previous configuration of the local repository, we renamed application.yml to application-local.yml.

This-local is a profile, and its value is-followed by, that is, local, we can specify which profile to use in bootstrap.yml. For example, in the actual project, the configuration of the development phase and the production phase is different, so there will be two or more configurations such as application-development.yml and application-production.yml.

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

Server: port: 8888spring: cloud: config: server: git: uri: https://gitee.com/zxuqian/spring-cloud-config-remote username: your gitee user name password: your gitee password

Because it is the warehouse of the self-use account, it does not provide the account password and changes it to its own corresponding. Here uri configures the address of the remote git repository.

Finally, enable our remote profile in bootstrap.yml:

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

Spring.profiles.active specifies our remote Profile, using the application-remote.yml configuration file.

test

Start our config server using spring-boot:run, then visit http://localhost:8888/web-client/default and see the following result:

{"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":" this message comes from the remote configuration repository", "management.endpoints.web.exposure.include": "*"}]}

The value of message is taken from the remote warehouse. Web-client/default here is the configuration file name / profile, because there is no other Profile in our web client project, then the default value is default. Only by writing it all in this way can you access the configuration of web-client.yml.

Tags: Configuration warehouse file project actual password message account phase project team development test different middle finger content only address base multiple customer Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Shulou Tech Info Docker vpn NVidia