Introduction
The SGIVU Config Repository uses Spring Cloud Config profiles to manage environment-specific configurations across development, production, and other environments. This approach allows you to maintain a single source of truth while providing environment-specific overrides.Spring Cloud Config Profile Mechanism
Base Configuration Files
Base configuration files follow the naming pattern{application}.yml and contain shared settings that apply to all environments:
- Common service configurations
- Default values with fallback using
${VAR:default} - Shared Spring Boot settings
- Service discovery configuration
- Management endpoints
Profile-Specific Overrides
Profile-specific files follow the pattern{application}-{profile}.yml and override or extend base configurations:
Naming Convention
Base Files
sgivu-auth.ymlsgivu-gateway.ymlsgivu-user.ymlsgivu-vehicle.ymlsgivu-client.ymlsgivu-purchase-sale.ymlsgivu-discovery.yml
Profile Files
sgivu-auth-dev.ymlsgivu-auth-prod.ymlsgivu-gateway-dev.ymlsgivu-gateway-prod.yml- And so on…
How Services Activate Profiles
Application Startup
Services activate profiles at startup using thespring.profiles.active property:
Docker Compose
Kubernetes
Profile Precedence and Override Rules
Spring Cloud Config merges configurations with profile-specific values taking precedence over base values.
Merge Behavior
-
Base configuration is loaded first
- All settings from
{application}.ymlare applied
- All settings from
-
Profile configuration is applied second
- Settings from
{application}-{profile}.ymloverride matching keys - New keys are added to the configuration
- Nested properties are merged at the leaf level
- Settings from
Example: Merged Configuration
Base (sgivu-auth.yml):
sgivu-auth-dev.yml):
Configuration Priority Order
When multiple configuration sources exist, Spring Boot applies them in this order (highest to lowest priority):Multiple Profiles
Spring Cloud Config supports multiple active profiles:Environment Variable Substitution
All configuration files support environment variable substitution with default values:- With default:
${DB_HOST:localhost}- useslocalhostifDB_HOSTis not set - Without default:
${DB_USERNAME}- application fails to start if not set
Best Practices
Use Base for Shared Config
Put common configurations that apply to all environments in base files
Override Sparingly
Only override what’s different in profile-specific files
Document Variables
Clearly document required environment variables and their purposes
Provide Defaults
Use default values for development convenience, but not for sensitive data
See Also
Dev Environment
Development environment configurations
Prod Environment
Production environment configurations
Environment Variables
Complete list of environment variables