Fix context-relative default value in XML parsing

This commit fixes the default value for the contextRelative attribute of
a RedirectView, when this view is registered via a
RedirectViewController in XML. The value is set to true.

Note that the default value for this is correctly documented in
spring-mvc-4.1.xsd. Also, the documentation and implementation for its
javadoc counterpart also enforces true as a default value.

Issue: SPR-12607
This commit is contained in:
Brian Clozel 2015-01-16 16:13:02 +01:00
parent 47fdac9214
commit 0c8d07fcff
2 changed files with 14 additions and 3 deletions

View File

@ -140,6 +140,8 @@ class ViewControllerBeanDefinitionParser implements BeanDefinitionParser {
}
if (element.hasAttribute("context-relative")) {
redirectView.getPropertyValues().add("contextRelative", element.getAttribute("context-relative"));
} else {
redirectView.getPropertyValues().add("contextRelative", true);
}
if (element.hasAttribute("keep-query-params")) {
redirectView.getPropertyValues().add("propagateQueryParams", element.getAttribute("keep-query-params"));

View File

@ -95,6 +95,7 @@ import org.springframework.web.servlet.handler.UserRoleAuthorizationInterceptor;
import org.springframework.web.servlet.handler.WebRequestHandlerInterceptorAdapter;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
import org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter;
import org.springframework.web.servlet.mvc.ParameterizableViewController;
import org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter;
import org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
@ -648,9 +649,17 @@ public class MvcNamespaceTests {
SimpleUrlHandlerMapping hm = this.appContext.getBean(SimpleUrlHandlerMapping.class);
assertNotNull(hm);
assertNotNull(hm.getUrlMap().get("/path"));
assertNotNull(hm.getUrlMap().get("/old"));
assertNotNull(hm.getUrlMap().get("/bad"));
ParameterizableViewController viewController = (ParameterizableViewController) hm.getUrlMap().get("/path");
assertNotNull(viewController);
assertEquals("home", viewController.getViewName());
ParameterizableViewController redirectViewController = (ParameterizableViewController) hm.getUrlMap().get("/old");
assertNotNull(redirectViewController);
assertThat(redirectViewController.getView(), Matchers.instanceOf(RedirectView.class));
ParameterizableViewController statusViewController = (ParameterizableViewController) hm.getUrlMap().get("/bad");
assertNotNull(statusViewController);
assertEquals(404, statusViewController.getStatusCode().value());
BeanNameUrlHandlerMapping beanNameMapping = this.appContext.getBean(BeanNameUrlHandlerMapping.class);
assertNotNull(beanNameMapping);