Implementing Configuration Management

1. Designing Configuration Hierarchy

SourcePriority (high to low)
Command-line args1
Environment variables2
External config (vault/server)3
Profile-specific file4
Default file (application.yml)5

2. Implementing Externalized Configuration

ToolUse
Spring Cloud ConfigCentralized git-backed
Consul / etcdDistributed KV
AWS Parameter Store / Secrets ManagerCloud-native
HashiCorp VaultSecrets + dynamic

3. Using Environment-Specific Configs

Example: Spring profiles

# application.yml (defaults)
server:
  port: 8080
---
spring:
  config:
    activate:
      on-profile: prod
server:
  port: 80
logging:
  level:
    root: WARN

4. Implementing Configuration Encryption

ApproachDetail
JasyptEncrypt values in YAML/properties
Sealed SecretsKubernetes-native
Vault TransitEncryption-as-a-service
SOPSMozilla, age/PGP/KMS backed

5. Implementing Feature Flags

TypeUse
Release toggleHide unfinished feature
ExperimentA/B test
Ops toggleKill switch
PermissionPer-user/tenant

Example: Flag check

if (flags.isEnabled("checkout.v2", userContext)) {
    return checkoutV2.run(cart);
}
return checkoutV1.run(cart);

6. Using Configuration Profiles

ProfilePurpose
local / devDeveloper machine
testCI / integration tests
stagingPre-prod parity
prodProduction

7. Implementing Dynamic Configuration Refresh

MechanismDetail
Spring @RefreshScopeBeans re-instantiated on refresh event
PollingPeriodic fetch of latest
Push (websocket/SSE)Server pushes changes
Watch streamsConsul/etcd watch APIs

8. Implementing Configuration Validation

Example: @ConfigurationProperties + @Validated

@ConfigurationProperties("app.payment")
@Validated
public record PaymentConfig(
    @NotBlank String apiKey,
    @Min(1) int connectTimeoutMs,
    @Min(1) int readTimeoutMs,
    @NotNull Duration retryBackoff) {}

9. Using Environment Variables

ConventionDetail
UPPER_SNAKEDATABASE_URL
Spring mappingapp.payment.api-keyAPP_PAYMENT_API_KEY
12-factorConfig in env, not code
Don't logEspecially secrets

10. Implementing Configuration Binding

ApproachDetail
@ValueSingle property; no validation
@ConfigurationPropertiesType-safe, validated, IDE autocomplete
RecordsImmutable config bean

11. Implementing Secret Management

PracticeDetail
Never commitgit-secrets, gitleaks pre-commit
Vault / KMSFetch at startup or runtime
RotationAuto-rotate; support multiple active
Least privilegePer-service IAM role
Audit accessLog who fetched what

12. Implementing Configuration Auditing

TrackDetail
WhoActor
WhatKey, before/after value (mask secrets)
WhenTimestamp
WhyOptional reason / ticket