Şuayb's BlogŞuayb's Blog
Home
Categories
Games
MediumAboutContact
Language
Theme
    1. Blog
    2. Programming
    3. Spring Boot Config Server

Spring Boot Config Server

PublishedFebruary 22, 2025
UpdatedFebruary 23, 2025
Reading time3 min read
JavaKotlinSpring BootSpring CloudConfig ServerMicroservice
XLinkedInFacebook
Spring Boot Config Server

Loading likes...

Spring Boot Config Server enables centralized configuration management for distributed applications, allowing dynamic configuration updates without requiring service restarts. This guide covers how to set up and use Spring Boot Config Server efficiently.


Last updatedFebruary 23, 2025

Total viewsLoading hits...

Previous articleSpring Boot Docker IntegrationNext articleSpring Boot Eureka Server
Şuayb Şimşek

Written by

Şuayb Şimşek

Backend-focused fullstack developer sharing practical notes on Spring Boot, security, microservices, and cloud-native architecture.

Expertise

  • Spring Boot
  • Go
  • Microservices
  • Next.js
  • Cloud Native

Connect

GitHubLinkedInMedium

Related posts

Spring Boot Circuit Breaker
Programming

Spring Boot Circuit Breaker

Learn how to implement Circuit Breaker in Spring Boot applications for resilient microservices.

March 13, 20253 min read
JavaKotlinSpring BootSpring CloudCircuit BreakerMicroservice
Spring Boot Eureka Server
Programming

Spring Boot Eureka Server

Learn how to set up and configure a Spring Boot Eureka Server for service discovery in microservices architecture.

February 23, 20253 min read
JavaKotlinSpring BootSpring CloudEureka ServerMicroservice
Spring Boot Kubernetes Integration
Programming

Spring Boot Kubernetes Integration

Learn how to deploy Spring Boot applications on Kubernetes for scalable, containerized microservices.

February 21, 20253 min read
JavaKotlinSpring BootKubernetesMicroserviceContainerization

About

Articles on Spring Boot, microservices, security, and more.

ContactStart here

Latest posts

  • Captain Tsubasa 2: World Fighters
  • Captain Tsubasa: Rise of New Champions
  • Spring Boot Configuration Properties
  • Spring Boot GraphQL JWE Authentication
  • Spring Boot JWE Authentication with JPA

Top topics

JavaKotlinSpring BootJWEJWTMicroservice

Subscribe

Get practical backend + fullstack notes when new articles are published.

Social

© 2024-2026 Şuayb's Blog. All rights reserved.

🌟 Why Use Config Server?

In this section, we clarify Why Use Config Server? and summarize the key points you will apply in implementation.

  • Centralized Configuration: Manage application settings in a single place.
  • Dynamic Updates: Update configurations without restarting services.
  • Environment Profiles: Support different configurations for dev, test, and production environments.
  • Security & Access Control: Store sensitive configurations securely.
  • Integration with Git: Keep configuration versions managed and trackable.

📋 Prerequisites

Ensure you have the following:

  • ☕ Java Development Kit (JDK) 17+
  • 📦 Maven or Gradle installed
  • 📁 Git Repository (for storing configurations)

🛠️ Step 1: Add Dependencies

Add the necessary dependencies for Spring Cloud Config Server.

Maven:

XMLpom.xml
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-config-server</artifactId>
</dependency>

Gradle:

GROOVYbuild.gradle
implementation 'org.springframework.cloud:spring-cloud-config-server'

🛠️ Step 2: Create the Config Server Application


🛠️ Step 3: Configure the Config Server

Create an application.yml file to specify the Git repository for storing configurations.

YAMLapplication.yml
server:
  port: 8888
spring:
  cloud:
    config:
      server:
        git:
          uri: https://github.com/example/config-repo
          default-label: main

Note: Replace https://github.com/example/config-repo with your actual Git repository.


🛠️ Step 4: Create a Configuration Repository

In your Git repository (e.g., config-repo), create an application.yml file with the following content:

YAMLconfig.yml
config.key: 'Hello from Config Server!'

Commit and push the file to the repository:

BASH
git add application.yml
git commit -m "Add config properties"
git push origin main

▶️ Running the Config Server

Start the Config Server application:

BASH
./mvnw spring-boot:run

or using Gradle:

BASH
gradle bootRun

Verify it is running by accessing:

BASH
curl -X GET http://localhost:8888/application/default

Expected Output:

JSONconfig.json
{
  "name": "application",
  "profiles": ["default"],
  "propertySources": [
    {
      "name": "https://github.com/example/config-repo/application.yml",
      "source": {
        "config.key": "Hello from Config Server!"
      }
    }
  ]
}

🛠️ Step 5: Configure a Client Application

In this section, we clarify Step 5: Configure a Client Application and summarize the key points you will apply in implementation.

Add Dependencies

First, include the Config Client starter so this service can pull centralized configuration during bootstrap.

Maven:

XMLpom.xml
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-config</artifactId>
</dependency>

Gradle:

GROOVYbuild.gradle
implementation 'org.springframework.cloud:spring-cloud-starter-config'

Client Application Configuration

In the client's bootstrap.yml, add the following:

YAMLapplication.yml
spring:
  application:
    name: config-client
  cloud:
    config:
      uri: http://localhost:8888

Client Application Code

The sample below provides a minimal client implementation so you can validate the server integration end to end.


▶️ Running the Client Application

Run the Config Client application:

BASH
./mvnw spring-boot:run

or using Gradle:

BASH
gradle bootRun

Retrieve the configuration from Config Server:

BASH
curl -X GET http://localhost:8080/config

Expected Output:

PLAINTEXTsnippet.txt
Config Value: Hello from Config Server!

🏁 Conclusion

You now have a practical Spring Boot Config Server implementation with a clear, production-friendly Spring Boot structure. As a next step, adapt configuration and tests to your own domain, then validate behavior under realistic traffic and failure scenarios.

JAVAConfigServerApplication.java
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);
    }
}
KOTLINConfigServerApplication.kt
package com.example.configserver

import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.cloud.config.server.EnableConfigServer

@SpringBootApplication
@EnableConfigServer
class ConfigServerApplication

fun main(args: Array<String>) {
    runApplication<ConfigServerApplication>(*args)
}
JAVAConfigClientApplication.java
package com.example.configclient;

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

@SpringBootApplication
@RestController
@RequestMapping("/config")
public class ConfigClientApplication {

  @Value("${config.key:not found}")
  private String configValue;

  @GetMapping
  public String getConfigValue() {
    return "Config Value: " + configValue;
  }

  public static void main(String[] args) {
    SpringApplication.run(ConfigClientApplication.class, args);
  }
}
KOTLINConfigClientApplication.kt
package com.example.configclient

import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import org.springframework.beans.factory.annotation.Value

@SpringBootApplication
@RestController
@RequestMapping("/config")
class ConfigClientApplication {

    @Value("\${config.key:not found}")
    lateinit var configValue: String

    @GetMapping
    fun getConfigValue(): String {
        return "Config Value: \$configValue"
    }
}

fun main(args: Array<String>) {
    runApplication<ConfigClientApplication>(*args)
}