Create Spring Cloud Config Server

Create Spring Cloud Config Server:-

This is one of the first steps to build microservices with Spring Cloud. This section emphasizes on building centralized configurations. We are going to create a Spring Cloud Config Server and centralize configurations needed for microservices.



In a traditional application, our configurations reside inside a file in the same project. We package the files and deploy them on a server. Now, if we need to change any configurations we need to repackage the code and redeploy. This becomes a tedious task in the microservices world as there could be multiple deployment and repackaging needed in a real-world scenario.

So the solution to above problem is Create Spring Cloud Config Server. The Config server gets the configuration from Github or File System and all microservices uses the configuration from the config server as shown below. Let’s see how can we achieve this?

Technologies Used:-

  • Java 8
  • Spring Boot
  • Maven 3
  • Git

Project Setup:-

Now create a simple Spring Boot app from Spring initializer as below and click on generate a project. We are going to choose Config Server dependency.

Spring-Cloud-Config-Project

@Enableconfigserver:-

We need to use this annotation while we Create Spring Cloud Config Server which says its a cloud config server and serve the configuration. Using this annotation, our app will be treated like a spring config server.




How Spring Cloud Config Server Stores Configuration:-

The Spring cloud config server stores configuration in two ways

  1. Git or SVN
  2. Using local File System

We are going to use a Github repository and store configuration in a properties file. We are going to create a properties file for each microservice. Let’s say I am going to build a service known as  user-service .So we are creating a user-service.properties for our service user-service and push it in our GitHub repository.

Let’s create a GitHub repository for Storing of Data by our Spring Cloud Config Server. You can fork my repository as well here.

Spring Cloud Config Server

Let’s create a file known as bootstrap.properties in resources folder.

 

Now let’s start Our Spring Cloud Config Server.

In the next post, we will see how we can create a Spring Cloud Config Client.




1 thought on “Create Spring Cloud Config Server

Leave a Reply

Your email address will not be published. Required fields are marked *