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.
