java.lang.IllegalStateException: Failed to load ApplicationContext (Spring test)
A Spring test could not create its application context.
Exact message you may see
Failed to load ApplicationContextIllegalStateException Failed to load ApplicationContext Meaning
The test starts the same wiring as the app. The root cause is in the nested exception: missing bean, bad property, database unavailable or wrong profile.
Common causes
- Missing test properties/profile
- Database not available in tests
- Missing mock for a dependency
- Configuration class not found
⚡ Quick fix
- Read the deepest
Caused by - Add
@ActiveProfiles("test")and test properties - Use
@MockBeanor Testcontainers
Detailed fix by platform
Spring Boot
@SpringBootTest @ActiveProfiles("test")withsrc/test/resources/application-test.properties
How to diagnose
- Cause — Root exception?
- Profile — Test profile?
- DB — Available?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Most viewed in Java
Other ways to find it
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Did this fix work for you?
Report a correction or suggest an improvement
Last updated 2 Dec 2026