When a command-line argument and an additional properties file set the same key, the effective value reaches the bound bean from the command line in this fixture.
Spring Boot file versus command line: assert the bound result
The collision test
The temporary file sets relay.batch-size=17 and relay.timeout=750ms. The application starts with --relay.batch-size=23. BootRelaySettingsTest asserts batchSize 23 and timeout 750 milliseconds on RelaySettings. Checking both fields matters: a mistaken global replacement could make the first assertion pass while discarding the file entirely.
This proves the ordering of the two sources in the checked Boot 4.0.8 startup path. It does not establish the ordering of every environment variable, imported location or platform secret. The file-only test isolates loading. The default-versus-CLI test isolates the older, narrower collision.
Report the effective value
A runbook that lists a value in application.properties but ignores launch arguments can describe the wrong worker capacity. Read the bound settings at startup or through a protected diagnostic endpoint. Redact secrets and retain the property origin only where operators need it.
For a poller, changing batch size changes database query work, heap allocation and per-tick duration. That is an operational choice, not only a syntax question. The polling budget explains the load consequence.
Checked source
try (var context = app().run(
"--spring.config.additional-location=" + configDirectory.toUri(),
"--relay.batch-size=23")) {
var settings = context.getBean(RelaySettings.class);
assertEquals(23, settings.batchSize());
assertEquals(Duration.ofMillis(750), settings.timeout());
}Verification boundary
BootRelaySettingsTest.commandLineOverridesAdditionalPropertiesFile. The excerpt is shortened or a labelled design sketch; the kit contains the checked tests.
Costs and limits
The test checks a local file and CLI against programmatic defaults. It does not set a real operating-system environment variable or exercise cloud configuration injection.
Common Mistakes
- Do not compare only raw Environment strings when callers use typed configuration beans.
- Do not assume one overridden key replaces every key from the file.
- Do not promote a test batch size into a production capacity recommendation.
Read next
Spring Boot external config file: bind the value the process actually loads, Spring Boot command-line properties: test the effective value at startup, Spring outbox polling: cap work per tick and measure backlog age, Spring Boot configuration sources: test each deployment path, not a guessed order.
