Centralized Configuration with Spring Cloud Config Server

As microservices scale, managing their configurations across environments becomes complex. Hardcoding properties in each service is inefficient and error-prone.

Spring Cloud Config Server solves this by providing a centralized way to serve external configuration for all environments and services, with support for version control systems like Git or SVN.

In this post, we’ll walk through how to create a Spring Cloud Config Server, connect it to a Git repo, and configure clients to fetch their properties at runtime.

Centralized Configuration with Spring Cloud Config Server

📦 Project Structure

🧰 Step 1: Set Up Spring Cloud Config Server

🔧 Dependencies (pom.xml)

Also include Spring Cloud BOM in dependencyManagement:

✅ Enable Config Server

⚙️ application.yml (for Config Server)

📁 Step 2: Prepare the Git Configuration Repository

Create a public or private Git repository such as:

🔧 Add configuration files:

product-service.yml:

You can create different files for environments:

  • product-service-dev.yml
  • product-service-prod.yml

🧩 Step 3: Configure Client (product-service)

🔧 Dependencies

📁 bootstrap.yml (in product-service)

🔧 application.yml

🔁 Step 4: Run and Test

✅ Steps:

  1. Start the Config Server on port 8888.
  2. Start product-service.
  3. Product-service will automatically fetch its config from:

You’ll see logs like:

🔄 Optional: Refresh Config at Runtime

Add spring-boot-actuator and enable /actuator/refresh:

Use a POST call to /actuator/refresh when configs change:

🔐 Secure Config Server (Optional)

You can secure access to the config server using Basic Auth or OAuth2:

📈 Benefits

  • ✅ Centralized configuration for all environments
  • ✅ Version-controlled using Git/SVN
  • ✅ Easy to manage updates and rollbacks
  • ✅ Dynamic refresh capability
  • ✅ Secure and scalable

🏁 Conclusion

Spring Cloud Config Server is an essential tool for managing microservice configurations at scale. By externalizing and centralizing configuration, it enables cleaner, more secure, and maintainable deployments across environments.

This approach is a cornerstone for building robust cloud-native applications.