Description
Per Holmberg opened SPR-9799 and commented
Overview
Test class extends AbstractTestNGSpringContextTests
and uses @ContextConfiguration
. It ran fine with XML-based configuration, but when I switched to Java-based configuration (with WebMvcConfigurationSupport
) it fails.
Excerpt from the stacktrace
java.lang.IllegalStateException: Failed to load ApplicationContext
...
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.web.servlet.HandlerMapping org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.defaultServletHandlerMapping()] threw exception; nested exception is java.lang.IllegalArgumentException: A ServletContext is required to configure default servlet handling
Analysis
There is no ServletContext
when running tests. So the message makes sense, but I thought that using @EnableWebMvc
or WebMvcConfigurationSupport
was equivalent to using <mvc:annotation-driven />
, but apparently it is not.
I could extend the WebMvcConfigurationSupport
and override the defaultServletHandlerMapping()
method as a work-around, but I don't think that should be necessary.
Further References
- See reference URL for another person having the same problem.
Affects: 3.1.2
Reference URL: http://forum.springsource.org/showthread.php?123151-Missing-servlet-context-in-spring-tests
Issue Links:
- Support loading WebApplicationContexts with the TestContext Framework [SPR-5243] #9917 Support loading WebApplicationContexts with the TestContext Framework ("is superseded by")
1 votes, 4 watchers