Spring Boot
Config Server
Microservices
Java
Configuration Management

Spring boot config server

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

Spring Cloud Config Server centralizes configuration for multiple services. Instead of baking environment-specific values into each application, you keep configuration in a shared backend such as Git and let services fetch it at startup.

This is useful in microservice systems where many applications need coordinated settings, profile-specific overrides, and a clear history of configuration changes. It also separates application code changes from operational config changes.

What the Config Server Does

Config Server is a normal Spring Boot application with the config server dependency enabled. It reads configuration from a backend repository and serves it over HTTP using conventions like /application/default or /orders-service/prod.

A Git-backed repository is the most common setup because it gives you version control, reviewable pull requests, and rollback history.

Build the Server

A minimal Maven setup needs Spring Boot and the Spring Cloud Config Server starter.

xml
1<dependencies>
2  <dependency>
3    <groupId>org.springframework.cloud</groupId>
4    <artifactId>spring-cloud-config-server</artifactId>
5  </dependency>
6</dependencies>

Enable the server in your main class:

java
1import org.springframework.boot.SpringApplication;
2import org.springframework.boot.autoconfigure.SpringBootApplication;
3import org.springframework.cloud.config.server.EnableConfigServer;
4
5@EnableConfigServer
6@SpringBootApplication
7public class ConfigServerApplication {
8    public static void main(String[] args) {
9        SpringApplication.run(ConfigServerApplication.class, args);
10    }
11}

Configure the Git backend in application.yml:

yaml
1server:
2  port: 8888
3
4spring:
5  cloud:
6    config:
7      server:
8        git:
9          uri: https://github.com/example/config-repo
10          default-label: main

When the server starts, it can serve files such as orders-service.yml, orders-service-prod.yml, or application.yml from that repository.

Configure a Client Service

A client service points to the config server and imports its configuration during startup.

yaml
1spring:
2  application:
3    name: orders-service
4  config:
5    import: optional:configserver:http://localhost:8888
6  profiles:
7    active: prod

When orders-service starts with the prod profile, it asks the config server for the merged configuration of orders-service and the shared application files.

Refreshing Configuration

Config values are usually loaded at startup, but some applications need runtime refresh. With Spring Actuator and @RefreshScope, a bean can reload values when the refresh endpoint is triggered.

java
1import org.springframework.beans.factory.annotation.Value;
2import org.springframework.cloud.context.config.annotation.RefreshScope;
3import org.springframework.web.bind.annotation.GetMapping;
4import org.springframework.web.bind.annotation.RestController;
5
6@RefreshScope
7@RestController
8public class MessageController {
9    @Value("${message:default}")
10    private String message;
11
12    @GetMapping("/message")
13    public String message() {
14        return message;
15    }
16}

This is useful, but do not overuse live refresh for every property. Some changes are safer with a controlled restart.

Secure the Configuration Path

Because config servers often distribute database credentials, API keys, and service endpoints, they must be protected. Use HTTPS, require authentication, and restrict network access. If you store secrets in Git, use encryption support or move secrets into a dedicated secret manager such as Vault.

Centralization improves manageability, but it also creates a high-value target. Treat the server and its backend repository as production-critical infrastructure.

Common Pitfalls

  • Putting secrets in plain text without access controls. A central config system magnifies the impact of weak secret handling.
  • Forgetting the client spring.application.name. Without it, the server cannot resolve the correct application-specific file set.
  • Assuming every property change can be refreshed safely at runtime. Some beans still need a restart.
  • Running config server without strong availability planning. If clients depend on it at startup, outages can cascade.
  • Mixing code and environment overrides inconsistently. A central config system only helps when teams use it predictably.

Summary

  • Spring Cloud Config Server centralizes external configuration for many services.
  • A Git backend is common because it provides history, review, and rollback.
  • Clients fetch config based on application name and active profile.
  • '@RefreshScope can reload selected values, but not every change should be live-refreshed.'
  • Secure the server carefully because it often distributes sensitive operational data.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.