How to Centralized Microservices configuration using Spring cloud?



Spring Cloud Config provides server and client modules for supporting externalized Configuration in a distributed system. With Config server, spring bootmicroservices configuration centralized across all environments.

The concept is similar to Environment, PropertySource in client applications. If the application moves from one profile to another profile, spring boot applications need not restarted, without downtime microservices will switch from one profile to another.

The default storage for these externalizes properties are git version system, as it supports branching, different properties for each configuration environment.

Spring Cloud Config Features:

  • Spring cloud Config provides the Rest API we can easily access the shared properties.

  • Encrypt and Decrypt configuration properties

  • Spring boot developers provides starter application, enable using @EnableConfigServer Spring cloud Config provides 2 ways to centralize the property source, one using the local properties file, other using git repository.

By default, the git repository used by default in the spring cloud config framework.

Project setup:

Add the below property in properties section.


Add the below dependencyManagement in pom.xml

<dependencyManagement> <dependencies> <dependency> <groupId></groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>

And add the below dependency:

<dependency> <groupId></groupId> <artifactId>spring-cloud-config-server</artifactId> </dependency>

@EnableConfigServer is the annotation is used to bootstrap the config server,add this annotation in any of the classes annotated with @Configuration or @SpringBootApplication. is the property used to configure the git repository.

JGitEnvironmentRepository is the class used to clone the provided git repository into the %TEMP% folder and start serving using these properties.

/{application}/{profile}[/{label}] /{application}-{profile}.yml /{label}/{application}-{profile}.yml /{application}-{profile}.properties /{label}/{application}-{profile}.properties

These are the endpoints provided by the spring config server, where the application injected as in the spring application. Normally application is the regular spring boot application the label is the git branch default to master.

When this HTTP server runs, it picks up the external configuration from the default local config server. By default, if no application name set, the application will be used. To modify name, the following property can add to file: myapp

The bootstrap properties show up in the /env endpoint as a high-priority property source

Main class if spring cloud config java file look like below:

@SpringBootApplication @EnableConfigServer publicclassConfigServerApplication { publicstaticvoid main(String[] args) {, args); } }

Skipping Git Server SSL Certification Validation:

In case if we are using local git server, we can skip SSL validation by using below property,

Setting HTTP Connection Timeout

We can configure the time in seconds the configuration server will acquire an HTTP Connection.


To use HTTP basic authentication on the remote repository, we can configure the username and password properties on the configuration file.






username: admin

password: adm1n

Refresh Repository:

We can control how often the config server will pull updated configuration data from your Git backend by using The value of this property specified in seconds. By default the value is 0, meaning the config server will fetch updated configuration from the Git repo every time it is requested.

Serving Configuration from GIT subpath:

Suppose based on requirement if need to load configuration properties from git repository subfolder then use property as follows:






search-paths: config

If we want to load from multiple subfolders, we can provide comma separated values.

Microservcies are now integral to most applications.

Your organization needs this upgrade with spring cloud. As enterprise solution providers, we offer this solution to support your configurations. Get in touch with us for the upgrade.

Serving Configuration from A Branch or Label:

By default, spring config server will load properties from a master, but we can configure this using property.

Serving application and profile specific properties:

Spring Config server can also provide the application and application profile based properties to its client.

Create a file named file, so that these properties file only available to bookservice application named microservice, these properties will override the default configuration file file.

We can also load profile specific properties using {application}-{profile}.properties(yml) file format. Suppose if a file named file is present, then it will be loaded only if none of the profiles are configured, will load bookservice service only if he is running in dev as an active profile in bookservice application.

Spring config server also supports Vault storage, which is used to storage the secured properties, like passwords, and SSL certificates, etc.


Spring Cloud Config server is the framework used to provide features to load and share with other microservice. Here, the best java programmer described different configuration properties file-related config server configuration. Also, we learned how to get application profile-based configuration properties using the config server and load the configuration properties other than the master branch.

Related article

Microservice architecture is a distributed system where multiple services collaborate with one another. They typically communicate with each other using REST API.

Microservices have become one of the enablers in the digital transformation journey as it is always focused and built on Business Need" and Single Responsibility. Microservices pattern enables scalability, speed, efficiency, and agility because of De-centralized API.

In this article, we will create a .net core microservice and create a code first database using entity framework 3.1.

DMCA Logo do not copy