Config Server
Spring cloud config server helps us to centrally manage external configuration for applications across all environments at run time.
It’s a part of the Spring Cloud suite and helps in managing application configuration in a distributed system — especially useful in microservice architecture.

Spring Cloud Config Server plays a critical role in enabling centralized and consistent configuration management across multiple microservices in a Spring Cloud environment.
It ensures that all services have access to the most up-to-date configuration properties at runtime.
In the example below, the Config Server retrieves configuration data properties from a remote Git repository. This Git-based configuration is then exposed and shared with various Spring Boot microservices, allowing each service to consume its corresponding configuration dynamically.
Additionally, the Config Server integrates with Spring Boot Actuator to expose endpoints that allow clients to view and refresh configurations. This enables real-time configuration updates without the need to restart individual services, promoting flexibility and improved operational efficiency in distributed systems.
Implementation
Below are the high level steps require to create Spring Cloud Config Server and consume within client projects:
- Create Git repo having all required application properties files in root folder.

2. Create Spring cloud config server to read application properties file from Git repo and expose same to different spring cloud client applications.
spring.cloud.config.server.git.uri=https://github.com/gitaccountname/configserver
3. Spring cloud client application to consume centralized configuration.
spring.config.import=configserver:http://localhost:8888
1. Centralized Configurations:
Create a Git repo to centrally manage the configurations for one or more applications.

2. Create Spring Cloud Config Server
Follow below steps to create spring cloud config server to expose configurations:
- Create Spring project to handle Spring Cloud configuration.

2. Import project in Intellij

3. Verify and validate below dependencies are there as part of pom.xml:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
4. Add @EnableConfigServer annotation on top of spring boot main class.

5. Create application.properties file and add application name, port and Git repo path to pick dynamic centralized application properties.

Spring Cloud Config Client
Setup config client in existing project to consume centralied application properties from Git repo with the help of config server:
- Add below dependency in pom.xml
<!-- pom.xml -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
2. Add below lines to pick dev profile and config server path in client project application.properties file:
server.port=8083
spring.application.name=order-service
spring.profiles.active=dev
spring.config.import=configserver:http://localhost:8888
Note: In above application properties file, it will load order-service-dev.properties file.
It will consider application-dev.properties file and than application.properties file if order-service-dev.properties doesn’t exists in Git repo.

3. Create a rest controller to read custom.order property value from config server and print:

OUTPUT:
Start both config server on port 8888 and config client on 8083.
Hitting URL http://localhost:8083/order in browser will show below output:

Get Updated property value without instance restart:
- Add dependency in config server pom.xml
<!-- Refresh dependency to load latest from Git application.properties /actuator/dependency -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
2. Change below custom.order property value and commit.

3. Trigger a POST refresh call to http://localhost:8888/actuator/refresh will return latest configurations at runtime.

4. Hitting URL http://localhost:8083/order in browser will give latest output:


Imran Khan, Adobe Community Advisor, certified AEM developer and Java Geek, is an experienced AEM developer with over 12 years of expertise in designing and implementing robust web applications. He leverages Adobe Experience Manager, Analytics, and Target to create dynamic digital experiences. Imran possesses extensive expertise in J2EE, Sightly, Struts 2.0, Spring, Hibernate, JPA, React, HTML, jQuery, and JavaScript.