A programmatic SpringApplication default has lower priority than configuration loaded from the application file in this checked startup path.
Spring Boot config source priority: a builder default may lose to a packaged file
A test that first used the wrong database
The source kit packages spring.datasource.url=jdbc:h2:mem:receipt_application. The first BootFlywayStartupTest supplied a unique H2 URL with SpringApplicationBuilder.properties. Boot still opened the packaged receipt_application database. Two test stages therefore touched the wrong shared database, and a supposed checksum failure did not occur. The test was corrected to pass the unique URL as a command-line argument.
This is a concrete reason to inspect the effective DataSource, not just a builder call. The settings fixture checks that CLI values reach a bound bean. The migration fixture now checks separate database histories across two context starts.
Protect isolation
A test URL that is accidentally shadowed can contaminate another test or make a migration appear repeatable for the wrong reason. Use an isolated database name, assert the expected schema history and inspect the connection URL when setup is ambiguous. Do not rely on tests passing in one fixed order.
The source kit uses H2 with DB_CLOSE_DELAY=-1 so two contexts can see the same named database during one test. That is deliberate for the V2-to-V3 trace. It is not a persistence guarantee across process restarts.
Checked source
return new SpringApplicationBuilder(MigrationApplication.class)
.web(WebApplicationType.NONE)
.properties("spring.flyway.locations=classpath:db/relay-migration")
.run("--spring.datasource.url=" + uniqueH2Url);Verification boundary
BootFlywayStartupTest.start uses a command-line URL; BootRelaySettingsTest checks file/default/CLI binding. The excerpt is shortened; the source kit contains the checked fixture.
Costs and limits
The verified collision is a packaged H2 URL versus a builder default. Other source combinations and a deployed database URL still require their own checks.
Common Mistakes
- Do not assume a builder default outranks application.properties.
- Do not share a fixed in-memory database name across isolation tests.
- Do not treat H2 memory lifetime as a restart test.
Read next
Spring Boot Flyway startup: apply versioned SQL before querying a receipt, Spring Boot configuration sources: test each deployment path, not a guessed order, Spring Boot command-line properties: test the effective value at startup, Spring Boot profile files: bind only the selected environment override.
