Spring Boot "@SpringBootTest failed to load ApplicationContext" in CI
JUnit could not build the Spring context for a @SpringBootTest, so every test in the class errors before running. The failure is a normal startup error surfaced through the test framework; read its Caused-by.
What this error means
Tests error (not fail) with "java.lang.IllegalStateException: Failed to load ApplicationContext", followed by the same Caused-by you would see at app startup.
Spring Boot
java.lang.IllegalStateException: Failed to load ApplicationContext for
[WebMergedContextConfiguration@...]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'dataSource' ...Common causes
A bean or resource fails only in CI
The context needs a DB, broker, or property that is present locally but missing on the runner, so the refresh throws.
The test profile is not the one you expect
CI activates a different (or no) profile, so config and beans differ and the context cannot assemble.
How to fix it
Trace the Caused-by like a startup error
- Read the innermost Caused-by under the IllegalStateException.
- Fix that root (provide the DB URL, activate the profile, define the bean).
- Re-run the failing test class.
Pin the test profile and provide its properties
Activate a dedicated test profile and supply everything it needs in CI.
src/test/java
@ActiveProfiles("test")
@SpringBootTest
class OrderFlowTest { }How to prevent it
- Give integration tests a self-contained test/ci profile.
- Provide DB and broker via Testcontainers so the context always assembles.
- Prefer slices over full context where a full app is not needed.
Related guides
Spring Boot "APPLICATION FAILED TO START" in CIFix the Spring Boot "APPLICATION FAILED TO START" banner in CI - the failure analyzer prints a Description an…
Spring Boot wrong spring.profiles.active in CIFix Spring Boot picking the wrong spring.profiles.active in CI - the runner loads dev/prod config instead of…
Spring Boot @DirtiesContext rebuilding the context in CIFix slow, memory-heavy Spring Boot CI caused by @DirtiesContext - it discards the cached context and rebuilds…