This is the 17th day of my participation in Gwen Challenge

“Configuration center Spring Cloud Config in detail” series of articles updated, together in the road of technology progress! This series of articles will introduce Spring Cloud Config, which provides a distributed configuration center in Spring Cloud. In addition to the code to realize system functions, application services also need to connect resources and other applications. There are often a lot of data that need to be configured externally to adjust the behavior of applications, such as switching different databases and setting function switches. With the increase of microservices, the system needs to be scalable and extensible, in addition to managing the configuration data of a considerable number of service instances. In the application development stage, each service is autonomous, but in the production environment, it will bring great trouble to the operation and maintenance, especially the micro service scale is relatively large, configuration update is more troublesome. Therefore, the system needs to establish a unified configuration management center.

In previous articles, we focused on the implementation details of the Spring Cloud Config client and server. The previous article described the advanced use of Config Server to configure multiple REPOs. This article describes how to override remote configuration properties for clients and use SVN or local file systems as configuration repositories.

The client overwrites the configuration properties of the remote

The configuration source of an application is usually the remote Config Server Server. By default, the local configuration takes precedence over the remote configuration repository. To enable local application system variables and config files to overwrite the attribute values in the remote repository, you can set the following parameters:

spring:
  cloud:
    config:
      allowOverride: true
      overrideNone: true
      overrideSystemProperties: false
Copy the code
  • OverrideNone: When allowOverride is true and overrideNone is set to true, the external configuration has lower priority and cannot override any existing attribute source. The default is false
  • AllowOverride: Indicates whether the overrideSystemProperties property is enabled. The default is true, and setting false disables the user’s Settings
  • OverrideSystemProperties: indicates whether external configurations can overrideSystemProperties. Default is true

The preceding configuration of the client service ensures that the local configuration has a higher priority and cannot be overwritten by the configuration in the remote repository.

Use the SVN or local file system as the repository

Git is used as the mainstream configuration repository in basic applications. This article will introduce how SVN repository and local file system are used as repositories.

SVN is the abbreviation of Subversion. It is an open source version control system. Through the efficient management of branch management system, it is used for multiple people to jointly develop the same project, realize the sharing of resources, and realize the final centralized management.

SVN adopts client/server system, various versions of the project are stored on the server, application developer from the server is first obtain a copy of the latest version of the project, and copy it to the machine, and then on this basis, each developer can be independent in their own client development work, and can at any time will be the new code is submitted to the server. You can also update to get the latest code on the server to keep it consistent with the versions used by other developers.

Let’s take a look at how to implement the repository based on SVN.

SVN

Add the following dependencies to the POM file in config Server:

<dependency>
	<groupId>org.tmatesoft.svnkit</groupId>
	<artifactId>svnkit</artifactId>
	<version>1.8.12</version>
</dependency>
Copy the code

The configuration of config Server in bootstrap.yml is as follows:

spring:
  cloud:
    config:
      server:
        svn:
          uri: svn://localhost:443/keets/config-repo
          username: user
          password: pwd
Copy the code

The “spring.profiles. Active “value of configServer startup is specified as SVN, so that the configServer is switched to SVN. For other features of SVN mode, we do not extend them here, and readers can consult the documentation.

summary

This article focuses on two advanced applications, the Spring Cloud Config client overwriting remote configuration properties and using SVN or local file system as the configuration repository. In the following articles, we will continue to learn about the application of Spring Cloud Config local file system configuration.