Make RequestMappingHandlerMapping xml config easier
Prior to this commit, it was necessary to override
the HandlerMapping definition to change properties
like useSuffixPatternMatch, useSuffixPatternMatch...
Also, one couldn't set custom pathmatcher/pathhelper
on RequestMappingHandlerMapping via XML configuration.
This commits adds a new "mvc:annotation-driven"
subelement called "mvc:path-matching" for the tag
that allows to configure such properties:
* suffix-pattern
* trailing-slash
* registered-suffixes-only
* path-matcher
* path-helper
Note: this is a new take on this issue, since
96b418cc has been reverted by e2b99c3.
Issue: SPR-10163
This commit is contained in:
@@ -125,6 +125,7 @@ import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolv
|
||||
* @author Juergen Hoeller
|
||||
* @author Arjen Poutsma
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Brian Clozel
|
||||
* @since 3.0
|
||||
*/
|
||||
class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser {
|
||||
@@ -172,6 +173,8 @@ class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser {
|
||||
handlerMappingDef.getPropertyValues().add("removeSemicolonContent", !enableMatrixVariables);
|
||||
}
|
||||
|
||||
configurePathMatchingProperties(handlerMappingDef, element);
|
||||
|
||||
RuntimeBeanReference conversionService = getConversionService(element, source, parserContext);
|
||||
RuntimeBeanReference validator = getValidator(element, source, parserContext);
|
||||
RuntimeBeanReference messageCodesResolver = getMessageCodesResolver(element);
|
||||
@@ -334,6 +337,33 @@ class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser {
|
||||
return contentNegotiationManagerRef;
|
||||
}
|
||||
|
||||
private void configurePathMatchingProperties(RootBeanDefinition handlerMappingDef, Element element) {
|
||||
|
||||
Element pathMatchingElement = DomUtils.getChildElementByTagName(element, "path-matching");
|
||||
if(pathMatchingElement != null) {
|
||||
if (pathMatchingElement.hasAttribute("suffix-pattern")) {
|
||||
Boolean useSuffixPatternMatch = Boolean.valueOf(pathMatchingElement.getAttribute("suffix-pattern"));
|
||||
handlerMappingDef.getPropertyValues().add("useSuffixPatternMatch", useSuffixPatternMatch);
|
||||
}
|
||||
if (pathMatchingElement.hasAttribute("trailing-slash")) {
|
||||
Boolean useTrailingSlashMatch = Boolean.valueOf(pathMatchingElement.getAttribute("trailing-slash"));
|
||||
handlerMappingDef.getPropertyValues().add("useTrailingSlashMatch", useTrailingSlashMatch);
|
||||
}
|
||||
if (pathMatchingElement.hasAttribute("registered-suffixes-only")) {
|
||||
Boolean useRegisteredSuffixPatternMatch = Boolean.valueOf(pathMatchingElement.getAttribute("registered-suffixes-only"));
|
||||
handlerMappingDef.getPropertyValues().add("useRegisteredSuffixPatternMatch", useRegisteredSuffixPatternMatch);
|
||||
}
|
||||
if (pathMatchingElement.hasAttribute("path-helper")) {
|
||||
RuntimeBeanReference pathHelperRef = new RuntimeBeanReference(pathMatchingElement.getAttribute("path-helper"));
|
||||
handlerMappingDef.getPropertyValues().add("urlPathHelper", pathHelperRef);
|
||||
}
|
||||
if (pathMatchingElement.hasAttribute("path-matcher")) {
|
||||
RuntimeBeanReference pathMatcherRef = new RuntimeBeanReference(pathMatchingElement.getAttribute("path-matcher"));
|
||||
handlerMappingDef.getPropertyValues().add("pathMatcher", pathMatcherRef);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Properties getDefaultMediaTypes() {
|
||||
Properties props = new Properties();
|
||||
if (romePresent) {
|
||||
|
||||
Reference in New Issue
Block a user