Spring Cloud Config Server+client [gradle, ssh authentication]

Hi friends, I have done some development on Spring Cloud Config Server in my current project. Let me provide you some input on it.

Why need Centralized Config Server ?

If you require too many microservices in your applications, managing each microservices configuration without restarting the service is a real deal. Spring Cloud is providing a wonderful Centralized approach to manage all the configs.

What we will build ?

  1. Spring-cloud-config-server [centralized config server]

2. Spring-cloud-client [Microservice to listen Spring-cloud-config-server for config changes]


3. spring-cloud-config [ to store all the configs]

Spring Config Server achitecture
We will build a Spring -cloud-config-server to centralize all the Configs in one place and build the Client Service to listen to the Centralized config server and without restarting the Client Server we can refresh the configs

Let’s build a Spring Cloud Config Server and a client.

  1. Spring-cloud-config-server:

Spring cloud config server (a spring boot microservice) will get all the configs from local storage or git repository.

2. Spring-cloud-client:

Spring cloud client service (a regular spring boot microservice) will listen to Spring cloud config server for all the configurations. Like.-

1. port
2. spring profiles
3. database config
4. rabbitmq or any other configs

Spring Client service is accessing the config from different location, instead of local application.yml or application.properties and in config changes we do not need to restart the Spring Client Server. Only do -

POST - http://localhost:{port}/refresh

Note: http://localhost:{port}/refresh will work only if the application is Spring boot Actuator application. Add the following dependency in you Spring Client Service build.gradle file


3. spring-cloud-config: We will store all the configs in this git repo

Spring Cloud Config Server basic Setup:

code: https://github.com/kousikpaul4u/Spring-cloud-config-server.git

Step 1: Create a Spring Starter Project. You can use Maven or Gradle dependency nature. Here we will use Gradle.

Step 2 : Modify build.gradle

code: https://github.com/kousikpaul4u/Spring-cloud-config-server/blob/master/build.gradle

Step 3: Add application.yml in src/main/resources

code: https://github.com/kousikpaul4u/Spring-cloud-config-server/blob/master/src/main/resources/application.yml

Note: In application.yml I am using following uri.

uri: https://github.com/kousikpaul4u/spring-cloud-config.git

In this git repository we can add multiple configurations. Spring Cloud Config Server will get all the configurations and Spring Client Services will listen the Spring Cloud Server to get the configs.

Step 4: Add @EnableConfigServer in root of the application class.

public class ConfigServiceApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServiceApplication.class, args);

Note: To run your own server use the spring-cloud-config-server dependency and @EnableConfigServer. If you set spring.config.name=configserver the app will run on port 8888 and serve data from a sample repository. You need a spring.cloud.config.server.git.uri to locate the configuration data for your own needs (by default it is the location of a git repository, and can be a local file:.. URL)

Step 5: Test Spring Cloud Config Server is properly working or not

Postman or browser hit following url:

GET http://localhost:8888/client1-dev/default

Note: Here we are fetching client1-dev.yml config from Spring Cloud Config Server


Response will be like:

 “name”: “client1-dev”,
 “profiles”: [
 “label”: “master”,
 “version”: “d29f1148c50f945f7c75d8bbe46b20fc6ab7f6f4”,
 “state”: null,
 “propertySources”: [
 “name”: “https://github.com/kousikpaul4u/spring-cloud-config.git/client1-dev.yml",
 “source”: {
 “service.name”: “Client1 Service”,
 “server.port”: 8200


code: https://github.com/kousikpaul4u/Spring-cloud-client.git

Step 1: Modify build.gradle

code: https://github.com/kousikpaul4u/Spring-cloud-client/blob/master/build.gradle

Step 2: Add bootstrap.yml in src/main/resources

code: https://github.com/kousikpaul4u/Spring-cloud-client/blob/master/src/main/resources/bootstrap.yml

Note: We have to specify which config file(.yml or .properties) Spring-cloud-client service will use.

spring.application.name: client1-dev

We have to also specify the Spring Cloud Config Server address.

cloud.config.uri: http://localhost:8888

Step 3: We can use @RefreshScope for specially treat Bean when Config will change. For more info regarding @RefreshScope please follow the below link.


Step 4: Now Client application will listen to config server application. If we want to get configs explicitly, we can write following code:

class MessageRestController {
private String name;
String getMessage() {
return this.name;

Step 5: Test the Client Service is working or not

After all the code base setup, we have to run Spring Cloud Config Server first then all the Client servers. Without configs, Client services will not determine the port to run, database connectivity etc configs.

Note: Without restarting we can not refresh the PORT number of a Client.

That's all.. It is pretty simple to build and easy to maintain the configs in centralized way. Please let me know if you have any query regarding this tutorial, I will be happy to help you :)

For Authentication to private git server like git , VSTS we can use credentials or SSH.

If you are using SSH key authentication, you can use the following config config-service application.yml

If you are using ssh key to connect private git repository use following commented configs

code: https://github.com/kousikpaul4u/Spring-cloud-config-server/blob/master/bin/application.yml
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.