A profile-specific properties file contributes settings when its named Spring profile is active.
Spring Boot profile files: bind only the selected environment override
The checked choice
BootRelaySettingsTest writes two files into a temporary directory. application.properties sets batch size 17 and timeout 750ms. application-review.properties sets batch size 29 only. The context starts with review active and the additional directory selected. The bound RelaySettings record reports 29 and 750ms. The profile file overrides one key; the base file still supplies the other.
The selected value matters to a background worker. A team can inspect the base file and assume 17 rows per tick while the deployed profile actually admits 29. The CLI collision test shows a further override. The polling budget explains why a larger batch needs load measurements.
Do not treat profile names as access control
A profile selects configuration. It does not authenticate a caller, hide a secret or prevent an operator from starting the wrong profile. Print the active profile and non-secret effective settings in a protected startup diagnostic. Check a real deployment with its selected file; this fixture uses local JUnit files.
If two profiles define the same key, define and test their order for that deployment. This test selects one profile and does not claim every multi-profile ordering rule. A required setting should still be validated after all selected sources are loaded.
Checked source
Files.writeString(dir.resolve("application.properties"),
"relay.batch-size=17\nrelay.timeout=750ms\n");
Files.writeString(dir.resolve("application-review.properties"),
"relay.batch-size=29\n");
try (var context = app().run("--spring.profiles.active=review",
"--spring.config.additional-location=" + dir.toUri())) {
assertEquals(29, context.getBean(RelaySettings.class).batchSize());
}Verification boundary
BootRelaySettingsTest.activeProfileLoadsItsFileOverTheBaseFile. The excerpt is shortened; the source kit contains the checked fixture.
Costs and limits
Only one local profile and a JUnit temporary directory are checked. No container mount, process environment variable, secret store or multi-profile collision is exercised.
Common Mistakes
- Do not read only the base file when a profile is active.
- Do not assume a profile is an authorization boundary.
- Do not size production batches from one local fixture.
Read next
Spring Boot external config file: bind the value the process actually loads, Spring Boot file versus command line: assert the bound result, Spring Boot configuration validation: reject an unusable relay before work starts, Spring outbox polling: cap work per tick and measure backlog age.
