Skip to content

Commit 0c8d07f

Browse files
committed
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
1 parent 47fdac9 commit 0c8d07f

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/config/ViewControllerBeanDefinitionParser.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ private RootBeanDefinition getRedirectView(Element element, HttpStatus status, O
140140
}
141141
if (element.hasAttribute("context-relative")) {
142142
redirectView.getPropertyValues().add("contextRelative", element.getAttribute("context-relative"));
143+
} else {
144+
redirectView.getPropertyValues().add("contextRelative", true);
143145
}
144146
if (element.hasAttribute("keep-query-params")) {
145147
redirectView.getPropertyValues().add("propagateQueryParams", element.getAttribute("keep-query-params"));

spring-webmvc/src/test/java/org/springframework/web/servlet/config/MvcNamespaceTests.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
import org.springframework.web.servlet.handler.WebRequestHandlerInterceptorAdapter;
9696
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
9797
import org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter;
98+
import org.springframework.web.servlet.mvc.ParameterizableViewController;
9899
import org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter;
99100
import org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder;
100101
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
@@ -648,9 +649,17 @@ public void testViewControllersDefaultConfig() {
648649

649650
SimpleUrlHandlerMapping hm = this.appContext.getBean(SimpleUrlHandlerMapping.class);
650651
assertNotNull(hm);
651-
assertNotNull(hm.getUrlMap().get("/path"));
652-
assertNotNull(hm.getUrlMap().get("/old"));
653-
assertNotNull(hm.getUrlMap().get("/bad"));
652+
ParameterizableViewController viewController = (ParameterizableViewController) hm.getUrlMap().get("/path");
653+
assertNotNull(viewController);
654+
assertEquals("home", viewController.getViewName());
655+
656+
ParameterizableViewController redirectViewController = (ParameterizableViewController) hm.getUrlMap().get("/old");
657+
assertNotNull(redirectViewController);
658+
assertThat(redirectViewController.getView(), Matchers.instanceOf(RedirectView.class));
659+
660+
ParameterizableViewController statusViewController = (ParameterizableViewController) hm.getUrlMap().get("/bad");
661+
assertNotNull(statusViewController);
662+
assertEquals(404, statusViewController.getStatusCode().value());
654663

655664
BeanNameUrlHandlerMapping beanNameMapping = this.appContext.getBean(BeanNameUrlHandlerMapping.class);
656665
assertNotNull(beanNameMapping);

0 commit comments

Comments
 (0)