Below is the complete, clean, and correct way to set up dev, qa, and prod environments using Spring Cloud Config Server.
This is the exact pattern used in real microservice deployments.
✅ 1. Repo Structure in Git (MOST IMPORTANT)
Your config-repo should look like:
config-repo/
│
├── auth-service.yml # common default config
├── auth-service-dev.yml # dev environment
├── auth-service-qa.yml # qa environment
└── auth-service-prod.yml # prod environment
You can do this for other microservices too:
config-repo/
├── gateway-service.yml
├── gateway-service-dev.yml
├── gateway-service-qa.yml
└── gateway-service-prod.yml
✔ suffix = profile
✔ Spring loads config like:
| File | Profile |
|---|---|
| auth-service.yml | default |
| auth-service-dev.yml | dev |
| auth-service-qa.yml | qa |
| auth-service-prod.yml | prod |
✅ 2. Config Server Setup
application.yml (Config Server)
server:
port: 8888
spring:
application:
name: config-server
cloud:
config:
server:
git:
uri: https://github.com/your-org/config-repo
default-label: main
clone-on-start: true
✔ No special setup needed for dev/qa/prod
✔ Automatically loads files by profile suffix
✅ 3. Client (Auth Service) Setup
Every microservice must have:
application.yml
spring:
application:
name: auth-service
config:
import: "optional:configserver:http://localhost:8888"
application-dev.yml
spring:
profiles:
active: dev
application-qa.yml
spring:
profiles:
active: qa
application-prod.yml
spring:
profiles:
active: prod
👉 You enable a profile by using:
java -jar auth-service.jar --spring.profiles.active=qa
or in IntelliJ run config:
--spring.profiles.active=dev
✅ 4. How Config Server Resolves Config
When you start:
java -jar auth-service.jar --spring.profiles.active=dev
Config Server loads:
auth-service.yml(default)auth-service-dev.yml(profile-specific)
Both are merged → dev overrides defaults
🧪 5. Test using URLs
Default
http://localhost:8888/auth-service/default
Dev
http://localhost:8888/auth-service/dev
QA
http://localhost:8888/auth-service/qa
Prod
http://localhost:8888/auth-service/prod
⭐ Example Files
auth-service.yml (Default)
server:
port: 9000
auth:
common-message: "Auth Service Default"
auth-service-dev.yml
server:
port: 9001
auth:
db-url: jdbc:postgresql://dev-db/auth
auth-service-qa.yml
server:
port: 9002
auth:
db-url: jdbc:postgresql://qa-db/auth
auth-service-prod.yml
server:
port: 9003
auth:
db-url: jdbc:postgresql://prod-db/auth
🎯 Best Practice (Used in Production)
| Environment | How to Run |
|---|---|
| Dev | --spring.profiles.active=dev |
| QA | --spring.profiles.active=qa |
| Prod | --spring.profiles.active=prod |
Each profile pulls its own config file from the Config Server.
