In this blog we ‘ll learn about spring boot cloud configuration server. Using spring boot cloud configuration server we can place all the configuration in one place instead of maintaining them in each microservice. For example say you have two microservice payment-service and order-service. So using spring boot cloud configuration server we can create config for these two microservice in one place and that payment and order microservice access there property using configuration server.
Here we are giving example of two microservice you can use as many service as you want. So you can see instead of creating and manage configuration in each microservice we can create them in one common place and each microservice access their properties from configuration server.
Let’s see how can we create the Spring boot cloud configuration server
it’s very easy to create spring boot cloud configuration server. We just need to follow some steps.
- Add below dependency in your pom.xml file.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>Code language: HTML, XML (xml)
2. Use @EnableConfigServer annotation on your main class. It enable and tells spring to behaves as config server.
package com.javadream.SpringConfigServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
@SpringBootApplication
@EnableConfigServer
public class SpringConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(SpringConfigServerApplication.class, args);
}
}Code language: JavaScript (javascript)
3. Create a folder and add configuration file inside that. In this example we created config-repo folder inside our project and add config file for order-service and payment-service. You can create folder and file as per your project.

4. Add below line in your application.properties file.
spring.application.name=SpringConfigServer
server.port=8888
spring.profiles.active=native
spring.cloud.config.server.native.search-locations=file:///C://Users//vasu//Downloads//SpringConfigServer//SpringConfigServer//config-repoCode language: JavaScript (javascript)
Let’s understand the above properties.
spring.profiles.active=native this property is use to set the active profile. Here we are using native because we are using FileSystem to manage configuration files. Means we create a folder in our system and create the properties file for each microservice.
By default spring boot uses git as configuration server. There are many way to create configuration server git is the default one and others are:
- Git Repository
- Native File System
- Classpath
- Vault (Hashicorp)
- Consul etc.
Above are some of the way where we can manage our configuration files. spring.profiles.active=native this native we use for Native File System and classpath. Native File System means we create a folder and create configuration file inside that. And for Classpath also we need to use active profile as native. If we use Classpath we need to create the configuration files inside /resource folder of our configuration server project.
spring.cloud.config.server.native.search-locations=file:///C://Users//vasu//Downloads//SpringConfigServer//SpringConfigServer//config-repo in this property we have to define the folder location that we are using. For this example we create a folder with name config-repo and create some configuration file inside that.
Important thing is file:/// . Make sure you add this file with three slashes whenever you are giving your folder path where your configuration stores. Else it ‘ll not able to find the folder. You can see for this property we give path of our folder just change with your folder name. Make sure you have some configuration file inside that.
Like for this example we are creating one application.yaml file and two property file for order and payment microservice.

application.yaml
app:
name: global-configCode language: PHP (php)
order-service-dev.yaml
server:
port: 8081
order:
db-url: jdbc:mysql://localhost:3306/orderdb_dev
cache-enabled: trueCode language: JavaScript (javascript)
payment-service-uat.yaml
server:
port: 8082
payment:
gateway: razorpay
currency: INR
Verify if properties are loading or not
That’s all we need to do. Now it’s time to verify that whatever changes we did they are working or not. So just run your application and verify the URL of configuration. URL is making with below details.
http://localhost:8888/<service-name>/<env-name>Code language: HTML, XML (xml)
In above URL http://localhost:8888 is the path of you spring boot configuration server if you are running on any different port just change it. after this we need to define service-name. So as you can see above we create some yaml file with name. order-service-dev.yaml is the property file for order-service microservice for dev env. So when you create your order-service microservice make sure your application name property must be order-service else it ‘ll not work. Same goes for payment-service-uat.yaml it’s a property file for payment-service for uat env. So for this also when you create this microservice make sure your name property ‘ll be payment-service.
Now it’s time to validate. If you don’t want to create these microservice as config client and want to validate if property are loading or not perfectly from configuration server directly, just run your spring boot configuration server and access the URL for each microservice.


If you are getting the response after running your spring boot configuration server congratulations your config server is ready.
Hope you like this blog. If you like please share this with others and help us to grow. Please share your feedback in our comment section.
If you need blog on any specific topic please mention in our comment section we ‘ll try to cover that in our upcoming blogs.
Others blog you may like
@Transactional annotation in spring boot complete step by step guide.
How to deploy spring boot application on Kubernetes.