Detect ControllerAdvice beans in ancestor contexts as well

Issue: SPR-11570
This commit is contained in:
Juergen Hoeller
2014-03-18 22:29:50 +01:00
parent b640b9fdfe
commit e0757e7ed6
3 changed files with 104 additions and 68 deletions

View File

@@ -45,7 +45,6 @@ import static org.junit.Assert.*;
* Unit tests for {@link RequestMappingHandlerAdapter}.
*
* @author Rossen Stoyanchev
*
* @see ServletAnnotationControllerHandlerMethodTests
* @see HandlerMethodAnnotationDetectionTests
* @see RequestMappingHandlerAdapterIntegrationTests
@@ -187,6 +186,22 @@ public class RequestMappingHandlerAdapterTests {
assertEquals("gAttr2", mav.getModel().get("attr2"));
}
@Test
public void modelAttributeAdviceInParentContext() throws Exception {
StaticWebApplicationContext parent = new StaticWebApplicationContext();
parent.registerSingleton("maa", ModelAttributeAdvice.class);
parent.refresh();
this.webAppContext.setParent(parent);
this.webAppContext.refresh();
HandlerMethod handlerMethod = handlerMethod(new SimpleController(), "handle");
this.handlerAdapter.afterPropertiesSet();
ModelAndView mav = this.handlerAdapter.handle(this.request, this.response, handlerMethod);
assertEquals("lAttr1", mav.getModel().get("attr1"));
assertEquals("gAttr2", mav.getModel().get("attr2"));
}
@Test
public void modelAttributePackageNameAdvice() throws Exception {
this.webAppContext.registerSingleton("mapa", ModelAttributePackageAdvice.class);