Set the ApplicationContext prop of ExceptionResolver
The MVC Java config now sets the ApplicationContext property of ExceptionHandlerExceptionResolver. Issue: SPR-9997
This commit is contained in:
@@ -44,8 +44,11 @@ import org.springframework.web.servlet.handler.AbstractHandlerMapping;
|
||||
import org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping;
|
||||
import org.springframework.web.servlet.handler.ConversionServiceExposingInterceptor;
|
||||
import org.springframework.web.servlet.handler.HandlerExceptionResolverComposite;
|
||||
import org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
|
||||
import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver;
|
||||
|
||||
/**
|
||||
* A test fixture with an {@link WebMvcConfigurationSupport} instance.
|
||||
@@ -56,20 +59,24 @@ public class WebMvcConfigurationSupportTests {
|
||||
|
||||
private WebMvcConfigurationSupport mvcConfiguration;
|
||||
|
||||
private StaticWebApplicationContext wac;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mvcConfiguration = new WebMvcConfigurationSupport();
|
||||
this.wac = new StaticWebApplicationContext();
|
||||
this.mvcConfiguration = new WebMvcConfigurationSupport();
|
||||
this.mvcConfiguration.setApplicationContext(wac);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestMappingHandlerMapping() throws Exception {
|
||||
StaticWebApplicationContext cxt = new StaticWebApplicationContext();
|
||||
cxt.registerSingleton("controller", TestController.class);
|
||||
this.wac.registerSingleton("controller", TestController.class);
|
||||
|
||||
RequestMappingHandlerMapping handlerMapping = mvcConfiguration.requestMappingHandlerMapping();
|
||||
assertEquals(0, handlerMapping.getOrder());
|
||||
|
||||
handlerMapping.setApplicationContext(cxt);
|
||||
handlerMapping.setApplicationContext(this.wac);
|
||||
handlerMapping.afterPropertiesSet();
|
||||
HandlerExecutionChain chain = handlerMapping.getHandler(new MockHttpServletRequest("GET", "/"));
|
||||
assertNotNull(chain.getInterceptors());
|
||||
@@ -146,9 +153,14 @@ public class WebMvcConfigurationSupportTests {
|
||||
|
||||
assertEquals(0, compositeResolver.getOrder());
|
||||
|
||||
List<HandlerExceptionResolver> expectedResolvers = new ArrayList<HandlerExceptionResolver>();
|
||||
mvcConfiguration.addDefaultHandlerExceptionResolvers(expectedResolvers);
|
||||
assertEquals(expectedResolvers.size(), compositeResolver.getExceptionResolvers().size());
|
||||
List<HandlerExceptionResolver> expectedResolvers = compositeResolver.getExceptionResolvers();
|
||||
|
||||
assertEquals(ExceptionHandlerExceptionResolver.class, expectedResolvers.get(0).getClass());
|
||||
assertEquals(ResponseStatusExceptionResolver.class, expectedResolvers.get(1).getClass());
|
||||
assertEquals(DefaultHandlerExceptionResolver.class, expectedResolvers.get(2).getClass());
|
||||
|
||||
ExceptionHandlerExceptionResolver eher = (ExceptionHandlerExceptionResolver) expectedResolvers.get(0);
|
||||
assertNotNull(eher.getApplicationContext());
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user