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
Configure the remote git repository
First, I created a remote repository on gitee https://gitee.com/zxuqian/spring-cloud-config-remote
to 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.yml
the message
value 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.yml
renamed it to application-local.yml
.
This -local
one is one profile
and its value is -
later, i.e. local
, we can bootstrap.yml
specify 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.yml
file 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. uri
The address of the remote git repository is configured here .
Finally bootstrap.yml
enable our remote
profile in:
spring:
application:
name: config-server
profiles:
active: remote
spring.profiles.active
That is, our remote
Profile is specified, and the application-remote.yml
configuration file is used.
test
Use to spring-boot:run
start 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":"*"}}]}
message
The value is taken from the remote repository. Here web-client/default
is 配置文件名/profile
, because our web client project has no other Profile, the default value is the configuration default
that can be accessed only by writing it all in this way web-client.yml
.