Config Server
Spring Cloud Config Server centralises externalised configuration for many Boot apps in a Git-backed (or native) repository.
Introduction
Spring Cloud Config Server centralises externalised configuration for many Boot apps in a Git-backed (or native) repository. Services import config at startup by application name and profile — change a property, refresh or restart, without rebuilding JARs.
On Boot 3, clients typically use spring.config.import=configserver:.... Keep secrets out of Git: reference a vault/secret manager, or encrypt with care — never commit real passwords to the config repo.
Modern Kubernetes estates often prefer ConfigMaps/Secrets plus Spring Cloud Kubernetes or external secret operators. Config Server remains widely used and interview-relevant; know both.
This lesson wires TechLearningPRO Orders to central config honestly alongside cloud-native alternatives.
Purpose of this lesson
Run a Git-backed Config Server and import shared Orders configuration safely without embedding secrets.
Understanding the topic
One config repo; many services; profile-specific overlays.
- Server:
@EnableConfigServerserving Git (or native) files. - Client:
spring.application.name+spring.config.import. - Files:
orders-service.yml,orders-service-prod.yml,application.yml. - Secrets: externalise — vault/K8s Secret — not plaintext in Git.
- Alt: ConfigMaps + Secrets + Spring Cloud Kubernetes reload.
Step-by-step explanation
- Create a config repo with
orders-service.ymlshared properties. - Boot a Config Server pointed at that Git URI (local file:// is fine for lab).
- In Orders, set application name and
spring.config.import=optional:configserver:http://config:8888. - Change a non-secret property and demonstrate restart/refresh picking it up.
Informative example
Config Server + Orders client import.
// config-server@SpringBootApplication@EnableConfigServerpublic class ConfigApp {public static void main(String[] args) {SpringApplication.run(ConfigApp.class, args);}}# config-server application.ymlserver.port: 8888spring:cloud:config:server:git:uri: https://github.com/acme/config-repodefault-label: main# orders-service bootstrap/applicationspring:application:name: orders-serviceconfig:import: optional:configserver:http://config:8888# config-repo/orders-service.ymlorders:checkout:max-lines: 50# passwords stay in Secret Manager / K8s Secret, e.g. ${DB_PASS}
Real-world use
TechLearningPRO once rebuilt Orders images to flip a feature flag. Config Server (and later ConfigMaps) moved that flag to data. A bad commit once put a database password in the Git config repo — rotation and secret-manager migration followed; the lesson stuck harder than any slide.
Security implications
Central config is high blast radius.
- Protect the config repo and server with auth and network policy.
- Never commit real credentials — use
${DB_PASS}placeholders. - Audit who can change prod overlays.
Best practices
- Git-back non-secret config for auditability; secrets elsewhere.
- Use profiles (
dev/prod) as overlays, not copy-paste sprawl. - On Kubernetes, evaluate ConfigMaps/Secrets before adding Config Server by habit.
Common mistakes
- Storing production passwords in the config Git repo.
- Optional import silently skipping config and running on unsafe defaults.
- Assuming @RefreshScope fixes every bean without understanding refresh semantics.
Advanced interview questions
Interview Prep
Practice concise answers, then expand each card for the explanation.
1BeginnerQuestionWhat does Spring Cloud Config Server provide?+
Answer
2IntermediateQuestionHow do Boot 3 clients import config?+
Answer
spring.config.import=configserver:... (optional: prefix for soft dependency).3IntermediateQuestionWhat is a cloud-native alternative?+
Answer
Hands-on exercise
Lab. Stand up Config Server with a local Git repo. Import orders.checkout.max-lines into Orders. Move a pretend DB password to an env var and prove the app fails fast if it is missing.
Summary
Config Server (or K8s config) keeps Orders settings out of rebuilds. Next: protect remote calls with the circuit breaker pattern.