skip to content

Config Server

A config server serves properties per application, profile and label from a git, Vault or filesystem backend. Interviewers ask why you would centralize configuration and what happens to your apps when the config server is down.

part ofSpring Frameworkoverview, primer and where to startread it →
on this pageshow

questions

6

What is Spring Cloud Config Server, and how do you turn a Spring Boot application into one?

level: juniorimportance: must knowfreq 78%

answer

  1. @EnableConfigServer + config-server starter
  2. central versioned config, git/native/vault backend
  3. serves /{application}/{profile}/{label} over HTTP
  4. client: spring.config.import=configserver:...
  5. read-side only; refresh & encryption are separate

basics

~10 s

It is a central server that stores application configuration (usually in git) and serves it to client apps over HTTP. You add the spring-cloud-config-server dependency and put @EnableConfigServer on the main class.

solid answer

~40 s

Spring Cloud Config Server externalizes configuration into a central, versioned place (git, filesystem, or Vault) instead of baking it into each service. Client applications fetch their properties from it over HTTP at startup, so many services share one source of truth and you can change config without rebuilding. You create it by adding the spring-cloud-config-server starter and annotating a @SpringBootApplication class with @EnableConfigServer, then pointing it at a backend, e.g. spring.cloud.config.server.git.uri. Clients declare spring.config.import=configserver:http://host:8888 (or the older bootstrap approach). The server exposes REST endpoints like /{application}/{profile}/{label} that return the merged property sources for that app, and it is the read side only — @RefreshScope reloading and encryption are separate concerns.

code

java · 19 lines
java
// build.gradle: implementation 'org.springframework.cloud:spring-cloud-config-server'

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

// application.yml
// server:
//   port: 8888
// spring:
//   cloud:
//     config:
//       server:
//         git:
//           uri: https://github.com/acme/config-repo

go deeper

for a junior

Know it centralizes config in git and that @EnableConfigServer + the starter creates the server; a client fetches its own properties by name.

for a middle

Explain server-vs-client split, the git.uri backend, and the client using spring.config.import; know it returns ordered property sources.

for a senior

Discuss why (single source of truth, versioning, central change control) and the scope boundary vs refresh/encryption; know EnvironmentController + EnvironmentRepository are what @EnableConfigServer wires.

for a principal

Weigh Config Server against alternatives (Kubernetes ConfigMaps, env vars, Consul), operational concerns like HA/caching, and when NOT to introduce it.

**The problem it solves.** In a microservice system every service needs configuration (DB URLs, feature flags, timeouts). Copying that into each deployable is fragile: no single source of truth, no history, and changing a value means rebuilding. Spring Cloud Config Server centralizes configuration in one place, keeps it versioned (git gives you history, diffs, rollback), and serves it to any number of client services over HTTP. **Server vs client.** There are two sides. The **Config Server** is a standalone Spring Boot app that reads a backend and exposes config over REST. **Config clients** are your normal services; at startup they call the server, download their properties, and add them to their own Spring `Environment`. **Making a server.** 1. Add the dependency `org.springframework.cloud:spring-cloud-config-server`. 2. Put `@EnableConfigServer` on a `@SpringBootApplication` class. This annotation imports the auto-configuration that wires up the `EnvironmentController` (the REST endpoints) and an `EnvironmentRepository` (the thing that actually reads the backend). 3. Configure a backend. The most common is git: `spring.cloud.config.server.git.uri=https://github.com/acme/config-repo`. Other backends: `native` (classpath/filesystem, good for local dev), `vault` (HashiCorp Vault for secrets), plus jdbc/redis. 4. Give the server a port, conventionally `server.port=8888`. **Making a client.** In Spring Boot 2.4+ the client adds `spring-cloud-starter-config` and sets `spring.config.import=configserver:http://localhost:8888` (older style used a `bootstrap.yml` with `spring.cloud.config.uri`). The client's `spring.application.name` becomes the `{application}` the server looks up, and its active Spring profiles become `{profile}`. **What the server returns.** For a request it produces an `Environment` object (a Spring Cloud DTO, not the core `org.springframework.core.env.Environment`) containing an ordered list of `PropertySource`s. The client merges these into its own environment following normal Spring precedence. **Scope boundaries (common confusion).** The Config Server is only the *serving* mechanism. Making a running client pick up changed values without a restart is `@RefreshScope` / the `/actuator/refresh` and bus — a separate feature. Encrypting/decrypting secret values (`{cipher}`) is also separate. This question is only about standing up the server and what it serves. **When to use.** Multiple services sharing config, needing audit history and central change control. For a single app, plain externalized `application.yml` or environment variables are simpler — don't add a Config Server just for one service.

  • How does a client know which configuration to request?
    Its spring.application.name maps to {application} and its active Spring profiles map to {profile}; it points at the server via spring.config.import=configserver:http://host:8888 (or older bootstrap spring.cloud.config.uri).
  • What happens on the server if you forget @EnableConfigServer?
    The config-server auto-configuration (EnvironmentController and EnvironmentRepository) is never imported, so the /{application}/{profile} endpoints don't exist and it behaves like an ordinary Boot app.

saying these in an interview costs you the question

  • Thinking @EnableConfigServer also live-reloads client beans (that is @RefreshScope).
  • Believing config can only live in git — native and Vault backends exist.
  • Confusing the Spring Cloud Environment DTO with core Spring Environment.

context

open as a page

Explain the /{application}/{profile}/{label} endpoint the Config Server exposes: what does each path variable mean and how does it map to files in the backend?

level: middleimportance: must knowfreq 70%

basics

~20 s

application is the client's spring.application.name, profile is its active profile(s), and label is the git branch/tag (defaults to main). The server maps these to files like {application}-{profile}.yml on that branch and returns their merged properties.

open as a page

What backends can a Config Server use to store configuration, and how do you configure git vs native?

level: middleimportance: should knowfreq 58%

basics

~10 s

Common backends are git (default, versioned), native (files on the classpath or filesystem, handy for local dev), and Vault (secrets). Git needs spring.cloud.config.server.git.uri; native is enabled with the 'native' profile and search-locations.

open as a page

What is the EnvironmentRepository abstraction, and what does its findOne(application, profile, label) return?

level: seniorimportance: should knowfreq 44%

basics

~20 s

EnvironmentRepository is the interface every Config Server backend implements. Its findOne(application, profile, label) method reads the backend and returns an Environment object holding an ordered list of PropertySources for that app/profile/label, which the client merges.

open as a page

Walk through how the Config Server resolves profiles and labels for a request, including precedence and the default label.

level: seniorimportance: should knowfreq 40%

basics

~20 s

Profiles pick which -{profile} files to include and how they layer (more specific wins over shared/base files). The label selects the git branch/tag/commit to read from; if the client sends none, the server's default-label (main, historically master) is used.

open as a page

How would you design a Config Server that maps different applications to different git repositories and combines multiple backends? What ordering rules apply?

level: principalimportance: nice to knowfreq 26%

basics

~20 s

Use pattern-based git repos (spring.cloud.config.server.git.repos) to route apps to specific repositories by name pattern, and the composite backend to combine sources like git plus Vault. Property sources from all matched repos are aggregated in configured order, most-specific first.

open as a page