# java.lang.IllegalStateException: Failed to load ApplicationContext (Spring test)

**Code:** `Failed to load ApplicationContext` · **Category:** Java · **Seen on:** Java, Spring Boot

A Spring test could not create its application context.

## 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

1. Read the deepest `Caused by`
2. Add `@ActiveProfiles("test")` and test properties
3. Use `@MockBean` or Testcontainers

## Detailed fix by platform

### Spring Boot

1. `@SpringBootTest @ActiveProfiles("test")` with `src/test/resources/application-test.properties`

## How to diagnose

1. **Cause** — Root exception?
2. **Profile** — Test profile?
3. **DB** — Available?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/java/spring-failed-to-load-applicationcontext)
