Failed to Load ApplicationContext during Spring unit test
I moved from spring 3.2.0 to 4.0.3 and had to update my javax.servlet dependency (in maven) from servlet 2.5 to servlet 3.0.1. The final dependency was
<dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.0.1</version> </dependency>
Then it worked
You'll need to annotate your test class with
@WebAppConfiguration
so that the test environment provides your WebApplicationContext
with a mock ServletContext
required by your MVC configuration.
Since a couple people mentioned Servlet version issues:
As of Spring 4.0 the set of mocks is now based on the Servlet 3.0 API.
You have two options:
- use 3.2.x spring-test dependency
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>3.2.14.RELEASE</version> <scope>test</scope> </dependency>
- upgrade to servlet 3.0
<dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.0.1</version> </dependency>