debugjavaspringModerate
Spring profiles: active profile not loaded because name is misspelled
Viewed 0 times
spring profilesactive profileapplication-prod.ymlprofile mismatchconfig activate on-profile
Problem
Defining a profile in application-prod.yml but activating spring.profiles.active=production causes Spring to load application.yml only; the prod file is silently ignored because the names do not match exactly.
Solution
The filename suffix must match the profile name character-for-character:
Verify active profiles on startup — Spring logs them at INFO level:
For multi-profile files in a single YAML document, use the
application-prod.yml -> spring.profiles.active=prod
application-production.yml -> spring.profiles.active=productionVerify active profiles on startup — Spring logs them at INFO level:
The following 1 profile is active: "prod"For multi-profile files in a single YAML document, use the
--- separator with spring.config.activate.on-profile:spring:
datasource:
url: jdbc:h2:mem:testdb
---
spring:
config:
activate:
on-profile: prod
datasource:
url: jdbc:postgresql://prod-host/mydbWhy
Spring's PropertySourceLoader resolves profile-specific files by appending the active profile name to the base filename. A mismatch produces no error; the file simply does not match the pattern and is not loaded.
Gotchas
- Profile names are case-sensitive on Linux/macOS filesystems
- Setting SPRING_PROFILES_ACTIVE environment variable overrides spring.profiles.active in application.yml
- Spring Boot 2.4+ changed multi-document YAML from
spring.profiles:tospring.config.activate.on-profile:
Revisions (0)
No revisions yet.