codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

Ā© 2026 codingstuff.io. All rights reserved.

Built with ā¤ļø for developers everywhere

/
/
All Tutorials
šŸƒ

Spring Boot

38 / 62 topics
35Microservices Basics with Spring Boot36Service Discovery with Eureka37API Gateway with Zuul38Spring Cloud Config Server39Circuit Breaker Pattern with Hystrix
Tutorials/Spring Boot/Spring Cloud Config Server
šŸƒSpring Boot

Spring Cloud Config Server

Updated 2026-04-20
4 min read

Introduction

Spring Cloud Config is a server and client solution for externalized configuration management in a distributed system. It provides a centralized way to manage configuration properties across multiple microservices, making it easier to maintain and update configurations without redeploying applications.

In this tutorial, we will explore how to set up and configure a Spring Cloud Config Server using Spring Boot. We'll cover the basics of setting up the server, integrating it with a client application, and best practices for managing configuration properties.

Prerequisites

Before you begin, ensure that you have the following:

  • Java Development Kit (JDK) 8 or later
  • Maven or Gradle build tool
  • Basic knowledge of Spring Boot and microservices architecture

Setting Up the Config Server

Step 1: Create a New Spring Boot Project

You can create a new Spring Boot project using Spring Initializr. Visit Spring Initializr and configure your project with the following settings:

  • Project: Maven Project
  • Language: Java
  • Spring Boot: Choose the latest stable version
  • Project Metadata:
    • Group: com.example
    • Artifact: config-server
    • Name: config-server
    • Description: Config Server
    • Package name: com.example.configserver
  • Packaging: Jar
  • Java: 8 or later

Add the following dependencies:

  • Spring Cloud Config Server

Click "Generate" to download the project. Extract the downloaded ZIP file and import it into your favorite IDE.

Step 2: Configure the Config Server

Open src/main/resources/application.properties and add the following configuration:

server.port=8888
spring.application.name=config-server
spring.cloud.config.server.git.uri=https://github.com/your-repo/config-repo

Replace https://github.com/your-repo/config-repo with the URL of your Git repository that contains the configuration files.

Step 3: Create Configuration Files in Git Repository

Create a new Git repository or use an existing one. Inside this repository, create configuration files for each microservice. For example:

config-repo/
ā”œā”€ā”€ application.properties
└── service-a.yml

application.properties can contain default configurations:

server.port=8080
management.endpoints.web.exposure.include=*

service-a.yml can contain specific configurations for service-a:

spring:
  application:
    name: service-a

custom:
  property: value

Step 4: Enable the Config Server

Open src/main/java/com/example/configserver/ConfigServerApplication.java and add the @EnableConfigServer annotation to enable the Config Server:

package com.example.configserver;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;

@SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication {

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

Step 5: Run the Config Server

Run the Spring Boot application. You can do this by executing the following command in your terminal:

mvn spring-boot:run

The Config Server should start on port 8888. You can verify its status by accessing http://localhost:8888.

Setting Up a Config Client

Step 1: Create a New Spring Boot Project for the Client

Create another Spring Boot project using Spring Initializr with the following settings:

  • Project: Maven Project
  • Language: Java
  • Spring Boot: Choose the latest stable version
  • Project Metadata:
    • Group: com.example
    • Artifact: service-a
    • Name: service-a
    • Description: Service A
    • Package name: com.example.servicea
  • Packaging: Jar
  • Java: 8 or later

Add the following dependencies:

  • Spring Cloud Config Client
  • Spring Web (for creating a simple REST controller)

Step 2: Configure the Config Client

Open src/main/resources/bootstrap.properties and add the following configuration to point to the Config Server:

spring.application.name=service-a
spring.cloud.config.uri=http://localhost:8888

Step 3: Create a Simple REST Controller

Create a new Java class in your client application to demonstrate accessing the configuration properties:

package com.example.servicea;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class ServiceAApplication {

    @Value("${custom.property}")
    private String customProperty;

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

    @GetMapping("/config")
    public String getConfig() {
        return "Custom Property: " + customProperty;
    }
}

Step 4: Run the Config Client

Run the Spring Boot application for the client. You can do this by executing the following command in your terminal:

mvn spring-boot:run

The client should start on its default port (usually 8080). Access http://localhost:8080/config to see the value of the custom property retrieved from the Config Server.

Best Practices

  1. Security: Always secure your Config Server using Spring Security or OAuth2 to prevent unauthorized access.
  2. Environment-Specific Configurations: Use profiles to manage environment-specific configurations (e.g., application-dev.properties, application-prod.yml).
  3. Version Control: Keep your configuration files in a version-controlled Git repository for easy management and rollback.
  4. Monitoring and Logging: Implement monitoring and logging to track changes and access patterns in the Config Server.

Conclusion

Spring Cloud Config Server provides a powerful way to manage configurations across multiple microservices. By centralizing configuration management, you can simplify deployment, improve maintainability, and enhance security in your microservices architecture. In this tutorial, we covered how to set up a Config Server and integrate it with a client application. Following best practices will help ensure that your configuration management is robust and scalable.

Feel free to explore additional features of Spring Cloud Config, such as support for other version control systems (e.g., SVN) and integration with distributed tracing tools like Zipkin or Jaeger.


PreviousAPI Gateway with ZuulNext Circuit Breaker Pattern with Hystrix

Recommended Gear

API Gateway with ZuulCircuit Breaker Pattern with Hystrix