Revert previous impl for SPR-10163

This reverts commit 96b418cc8a,
"Make RequestMappingHandlerMapping xml config easier".

This implementation makes the mvc:annotation namespace less readable,
and future configuration items would add even more to this namespace.

Issue: SPR-10163
This commit is contained in:
Brian Clozel 2014-01-17 20:07:30 +01:00
parent 17e492e641
commit 8edb7a18cc
5 changed files with 6 additions and 85 deletions

View File

@ -171,19 +171,6 @@ class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser {
Boolean enableMatrixVariables = Boolean.valueOf(element.getAttribute("enableMatrixVariables"));
handlerMappingDef.getPropertyValues().add("removeSemicolonContent", !enableMatrixVariables);
}
if(element.hasAttribute("use-suffix-pattern-match")) {
handlerMappingDef.getPropertyValues().add("useSuffixPatternMatch",
Boolean.valueOf(element.getAttribute("use-suffix-pattern-match")));
}
if(element.hasAttribute("use-trailing-slash-match")) {
handlerMappingDef.getPropertyValues().add("useTrailingSlashMatch",
Boolean.valueOf(element.getAttribute("use-trailing-slash-match")));
}
if(element.hasAttribute("use-registered-suffix-pattern-match")) {
handlerMappingDef.getPropertyValues().add("useRegisteredSuffixPatternMatch",
Boolean.valueOf(element.getAttribute("use-registered-suffix-pattern-match")));
}
RuntimeBeanReference conversionService = getConversionService(element, source, parserContext);
RuntimeBeanReference validator = getValidator(element, source, parserContext);

View File

@ -255,35 +255,6 @@
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="use-suffix-pattern-match" type="xsd:boolean">
<xsd:annotation>
<xsd:documentation><![CDATA[
Whether to use suffix pattern match (".*") when matching patterns to requests. If enabled
a method mapped to "/users" also matches to "/users.*". The default value is true.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="use-trailing-slash-match" type="xsd:boolean">
<xsd:annotation>
<xsd:documentation><![CDATA[
Whether to match to URLs irrespective of the presence of a trailing slash.
If enabled a method mapped to "/users" also matches to "/users/".
The default value is true.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="use-registered-suffix-pattern-match" type="xsd:boolean">
<xsd:annotation>
<xsd:documentation><![CDATA[
Whether to use suffix pattern match for registered file extensions only when matching patterns to requests.
If enabled, a controller method mapped to "/users" also matches to "/users.json" assuming ".json" is a file extension registered with
the provided ContentNegotiationManager. This can be useful for allowing only specific URL extensions to be used as well as in cases
where a "." in the URL path can lead to ambiguous interpretation of path variable content, (e.g. given "/users/{user}" and incoming
URLs such as "/users/john.j.joe" and "/users/john.j.joe.json").
If enabled, this attribute also enables use-suffix-pattern-match. The default value is false.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
</xsd:element>

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -15,6 +15,10 @@
*/
package org.springframework.web.servlet.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.List;
import org.junit.Before;
@ -38,16 +42,11 @@ import org.springframework.web.method.support.ModelAndViewContainer;
import org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
import org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import org.springframework.web.servlet.mvc.method.annotation.ServletWebArgumentResolverAdapter;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
/**
* Test fixture for the configuration in mvc-config-annotation-driven.xml.
* @author Rossen Stoyanchev
* @author Brian Clozel
*/
public class AnnotationDrivenBeanDefinitionParserTests {
@ -71,28 +70,6 @@ public class AnnotationDrivenBeanDefinitionParserTests {
assertEquals(false, new DirectFieldAccessor(adapter).getPropertyValue("ignoreDefaultModelOnRedirect"));
}
@Test
public void testCustomContentNegotiationManager() {
loadBeanDefinitions("mvc-config-content-negotiation-manager.xml");
RequestMappingHandlerMapping hm = appContext.getBean(RequestMappingHandlerMapping.class);
assertNotNull(hm);
assertTrue(hm.useSuffixPatternMatch());
assertTrue(hm.useRegisteredSuffixPatternMatch());
List<String> fileExtensions = hm.getContentNegotiationManager().getAllFileExtensions();
assertThat(fileExtensions, contains("xml"));
assertThat(fileExtensions, hasSize(1));
}
@Test
public void testRequestMappingCustomAttributes() {
loadBeanDefinitions("mvc-config-custom-attributes.xml");
RequestMappingHandlerMapping hm = appContext.getBean(RequestMappingHandlerMapping.class);
assertNotNull(hm);
assertFalse(hm.getUrlPathHelper().shouldRemoveSemicolonContent());
assertFalse(hm.useTrailingSlashMatch());
assertFalse(hm.useSuffixPatternMatch());
}
@Test
public void testMessageConverters() {
loadBeanDefinitions("mvc-config-message-converters.xml");

View File

@ -5,8 +5,7 @@
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<mvc:annotation-driven content-negotiation-manager="contentNegotiationManager"
use-registered-suffix-pattern-match="true"/>
<mvc:annotation-driven content-negotiation-manager="contentNegotiationManager" />
<bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
<property name="mediaTypes">

View File

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<mvc:annotation-driven
use-trailing-slash-match="false"
use-suffix-pattern-match="false"
enable-matrix-variables="true"
/>
</beans>