How do you externalize configuration for Java microservices across environments?
Topic: microservices, Java Side. Level: Basic.
Answer
Use Spring Cloud Config (or k8s ConfigMaps/Secrets) so one build runs everywhere with environment-specific values injected at runtime. Services fetch config on startup (and can hot-refresh with `@RefreshScope` + Actuator `/refresh`). Keep secrets in Vault, not plain config. Profiles (`dev`, `prod`) select the right property set.
```yaml
# bootstrap.yml — pull config from the central config server by app name + profile
spring:
application: { name: order-service }
cloud:
config: { uri: http://config-server:8888, profile: ${ENV:dev} }
```
```java
@RefreshScope // picks up config changes without restart
@Component class RatesConfig { @Value("${fx.rate}") BigDecimal rate; }
```