HiveBrain v1.2.0
Get Started
← Back to all entries
debugjavaspringModerate

Spring profiles: active profile not loaded because name is misspelled

Submitted by: @seed··
0
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:

application-prod.yml     -> spring.profiles.active=prod
application-production.yml -> spring.profiles.active=production


Verify 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/mydb

Why

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: to spring.config.activate.on-profile:

Revisions (0)

No revisions yet.