renamed "mapping-order" to "order"; added "cache-period"
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@3598 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
parent
628eff0773
commit
fded7496d5
|
|
@ -16,14 +16,12 @@
|
||||||
|
|
||||||
package org.springframework.web.servlet.config;
|
package org.springframework.web.servlet.config;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
import org.springframework.beans.factory.config.BeanDefinition;
|
import org.springframework.beans.factory.config.BeanDefinition;
|
||||||
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
|
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
|
||||||
import org.springframework.beans.factory.support.ManagedList;
|
|
||||||
import org.springframework.beans.factory.support.ManagedMap;
|
import org.springframework.beans.factory.support.ManagedMap;
|
||||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||||
import org.springframework.beans.factory.xml.BeanDefinitionParser;
|
import org.springframework.beans.factory.xml.BeanDefinitionParser;
|
||||||
|
|
@ -54,7 +52,7 @@ class ResourcesBeanDefinitionParser extends AbstractHttpRequestHandlerBeanDefini
|
||||||
|
|
||||||
private void registerResourceMappings(ParserContext parserContext, Element element, Object source) {
|
private void registerResourceMappings(ParserContext parserContext, Element element, Object source) {
|
||||||
String resourceHandlerName = registerResourceHandler(parserContext, element, source);
|
String resourceHandlerName = registerResourceHandler(parserContext, element, source);
|
||||||
if (!StringUtils.hasText(resourceHandlerName)) {
|
if (resourceHandlerName == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -71,8 +69,9 @@ class ResourcesBeanDefinitionParser extends AbstractHttpRequestHandlerBeanDefini
|
||||||
handlerMappingDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
|
handlerMappingDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
|
||||||
handlerMappingDef.getPropertyValues().add("urlMap", urlMap);
|
handlerMappingDef.getPropertyValues().add("urlMap", urlMap);
|
||||||
|
|
||||||
String mappingOrder = element.getAttribute("mapping-order");
|
String order = element.getAttribute("order");
|
||||||
handlerMappingDef.getPropertyValues().add("order", StringUtils.hasText(mappingOrder) ? mappingOrder : Ordered.LOWEST_PRECEDENCE - 1);
|
// use a default of near-lowest precedence, still allowing for even lower precedence in other mappings
|
||||||
|
handlerMappingDef.getPropertyValues().add("order", StringUtils.hasText(order) ? order : Ordered.LOWEST_PRECEDENCE - 1);
|
||||||
|
|
||||||
String beanName = parserContext.getReaderContext().generateBeanName(handlerMappingDef);
|
String beanName = parserContext.getReaderContext().generateBeanName(handlerMappingDef);
|
||||||
parserContext.getRegistry().registerBeanDefinition(beanName, handlerMappingDef);
|
parserContext.getRegistry().registerBeanDefinition(beanName, handlerMappingDef);
|
||||||
|
|
@ -83,20 +82,23 @@ class ResourcesBeanDefinitionParser extends AbstractHttpRequestHandlerBeanDefini
|
||||||
String locationAttr = element.getAttribute("location");
|
String locationAttr = element.getAttribute("location");
|
||||||
if (!StringUtils.hasText(locationAttr)) {
|
if (!StringUtils.hasText(locationAttr)) {
|
||||||
parserContext.getReaderContext().error("The 'location' attribute is required.", parserContext.extractSource(element));
|
parserContext.getReaderContext().error("The 'location' attribute is required.", parserContext.extractSource(element));
|
||||||
return "";
|
return null;
|
||||||
}
|
}
|
||||||
String[] locationPatterns = locationAttr.split(",\\s*");
|
|
||||||
List<String> locations = new ManagedList<String>();
|
|
||||||
for (String location : locationPatterns) {
|
|
||||||
locations.add(location);
|
|
||||||
}
|
|
||||||
RootBeanDefinition resourceHandlerDef = new RootBeanDefinition(ResourceHttpRequestHandler.class);
|
RootBeanDefinition resourceHandlerDef = new RootBeanDefinition(ResourceHttpRequestHandler.class);
|
||||||
resourceHandlerDef.setSource(source);
|
resourceHandlerDef.setSource(source);
|
||||||
resourceHandlerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
|
resourceHandlerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
|
||||||
resourceHandlerDef.getPropertyValues().add("locations", locations);
|
resourceHandlerDef.getPropertyValues().add("locations", StringUtils.commaDelimitedListToStringArray(locationAttr));
|
||||||
|
|
||||||
|
String cacheSeconds = element.getAttribute("cache-period");
|
||||||
|
if (StringUtils.hasText(cacheSeconds)) {
|
||||||
|
resourceHandlerDef.getPropertyValues().add("cacheSeconds", cacheSeconds);
|
||||||
|
}
|
||||||
|
|
||||||
String beanName = parserContext.getReaderContext().generateBeanName(resourceHandlerDef);
|
String beanName = parserContext.getReaderContext().generateBeanName(resourceHandlerDef);
|
||||||
parserContext.getRegistry().registerBeanDefinition(beanName, resourceHandlerDef);
|
parserContext.getRegistry().registerBeanDefinition(beanName, resourceHandlerDef);
|
||||||
parserContext.registerComponent(new BeanComponentDefinition(resourceHandlerDef, beanName));
|
parserContext.registerComponent(new BeanComponentDefinition(resourceHandlerDef, beanName));
|
||||||
return beanName;
|
return beanName;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,7 @@
|
||||||
|
|
||||||
<xsd:element name="annotation-driven">
|
<xsd:element name="annotation-driven">
|
||||||
<xsd:annotation>
|
<xsd:annotation>
|
||||||
<xsd:documentation
|
<xsd:documentation source="java:org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"><![CDATA[
|
||||||
source="java:org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"><![CDATA[
|
|
||||||
Configures the annotation-driven Spring MVC Controller programming model.
|
Configures the annotation-driven Spring MVC Controller programming model.
|
||||||
Note that, with Spring 3.0, this tag works in Servlet MVC only!
|
Note that, with Spring 3.0, this tag works in Servlet MVC only!
|
||||||
]]></xsd:documentation>
|
]]></xsd:documentation>
|
||||||
|
|
@ -54,41 +53,49 @@
|
||||||
<xsd:documentation
|
<xsd:documentation
|
||||||
source="java:org.springframework.web.servlet.resource.ResourceHttpRequestHandler"><![CDATA[
|
source="java:org.springframework.web.servlet.resource.ResourceHttpRequestHandler"><![CDATA[
|
||||||
Configures a handler for serving static resources such as images, js, and, css files with cache headers optimized for efficient
|
Configures a handler for serving static resources such as images, js, and, css files with cache headers optimized for efficient
|
||||||
loading in a web browser. Allows resources to be served out of any path that is reachable via Spring's Resource handling.
|
loading in a web browser. Allows resources to be served out of any path that is reachable via Spring's Resource handling.
|
||||||
]]></xsd:documentation>
|
]]></xsd:documentation>
|
||||||
</xsd:annotation>
|
</xsd:annotation>
|
||||||
<xsd:complexType>
|
<xsd:complexType>
|
||||||
<xsd:attribute name="mapping" use="required" type="xsd:string">
|
<xsd:attribute name="mapping" use="required" type="xsd:string">
|
||||||
<xsd:annotation>
|
<xsd:annotation>
|
||||||
<xsd:documentation>
|
<xsd:documentation><![CDATA[
|
||||||
<![CDATA[
|
The URL mapping pattern, within the current Servlet context, to use for serving resources from this handler, such as "/resources/**"
|
||||||
The URL mapping pattern, within the current Sevlet context, to use for serving resources from this handler, such as "/resources/**"
|
]]></xsd:documentation>
|
||||||
]]>
|
|
||||||
</xsd:documentation>
|
|
||||||
</xsd:annotation>
|
</xsd:annotation>
|
||||||
</xsd:attribute>
|
</xsd:attribute>
|
||||||
<xsd:attribute name="location" use="required" type="xsd:string">
|
<xsd:attribute name="location" use="required" type="xsd:string">
|
||||||
<xsd:annotation>
|
<xsd:annotation>
|
||||||
<xsd:documentation>
|
<xsd:documentation><![CDATA[
|
||||||
<![CDATA[
|
The resource location from which to serve static content, specified at a Spring Resource pattern.
|
||||||
The resource location from which to serve static content, specified at a Spring Resource pattern. Each location must point to a valid directory.
|
Each location must point to a valid directory. Multiple locations may be specified as a comma-separated list,
|
||||||
Multiple locations may be specified as a comma-seperated list, and the locations will be checked for a given resource in the order specified. For example,
|
and the locations will be checked for a given resource in the order specified. For example, a value of
|
||||||
a value of "/, classpath:/META-INF/public-web-resources/" will allow resources to be served both from the web app root and from any JAR on the classpath
|
"/, classpath:/META-INF/public-web-resources/" will allow resources to be served both from the web app
|
||||||
that contains a /META-INF/public-web-resources/ directory, with resources in the web app root taking precedence.
|
root and from any JAR on the classpath that contains a /META-INF/public-web-resources/ directory,
|
||||||
]]>
|
with resources in the web app root taking precedence.
|
||||||
</xsd:documentation>
|
]]></xsd:documentation>
|
||||||
</xsd:annotation>
|
</xsd:annotation>
|
||||||
</xsd:attribute>
|
</xsd:attribute>
|
||||||
<xsd:attribute name="mapping-order" type="xsd:string">
|
<xsd:attribute name="cache-period" type="xsd:string">
|
||||||
<xsd:annotation>
|
<xsd:annotation>
|
||||||
<xsd:documentation>
|
<xsd:documentation>
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
Specifies the order of the HandlerMapping for the resource handler. The default order is Ordered.LOWEST_PRECEDENCE - 1.
|
Specifies the cache period for the resources served by this resource handler, in seconds.
|
||||||
]]>
|
The default is to not send any cache headers but rather to rely on last-modified timestamps only.
|
||||||
</xsd:documentation>
|
Set this to 0 in order to send cache headers that prevent caching, or to a positive number of
|
||||||
|
seconds in order to send cache headers with the given max-age value.
|
||||||
|
]]></xsd:documentation>
|
||||||
</xsd:annotation>
|
</xsd:annotation>
|
||||||
</xsd:attribute>
|
</xsd:attribute>
|
||||||
</xsd:complexType>
|
<xsd:attribute name="order" type="xsd:int">
|
||||||
|
<xsd:annotation>
|
||||||
|
<xsd:documentation>
|
||||||
|
<![CDATA[
|
||||||
|
Specifies the order of the HandlerMapping for the resource handler. The default order is Ordered.LOWEST_PRECEDENCE - 1.
|
||||||
|
]]></xsd:documentation>
|
||||||
|
</xsd:annotation>
|
||||||
|
</xsd:attribute>
|
||||||
|
</xsd:complexType>
|
||||||
</xsd:element>
|
</xsd:element>
|
||||||
|
|
||||||
<xsd:element name="default-servlet-handler">
|
<xsd:element name="default-servlet-handler">
|
||||||
|
|
|
||||||
|
|
@ -203,7 +203,6 @@ public class MvcNamespaceTests {
|
||||||
chain = mapping.getHandler(request);
|
chain = mapping.getHandler(request);
|
||||||
assertEquals(5, chain.getInterceptors().length);
|
assertEquals(5, chain.getInterceptors().length);
|
||||||
assertTrue(chain.getInterceptors()[4] instanceof WebRequestHandlerInterceptorAdapter);
|
assertTrue(chain.getInterceptors()[4] instanceof WebRequestHandlerInterceptorAdapter);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -465,7 +464,6 @@ public class MvcNamespaceTests {
|
||||||
public void validate(Object target, Errors errors) {
|
public void validate(Object target, Errors errors) {
|
||||||
this.validatorInvoked = true;
|
this.validatorInvoked = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class TestBean {
|
private static class TestBean {
|
||||||
|
|
@ -482,7 +480,6 @@ public class MvcNamespaceTests {
|
||||||
public void setField(String field) {
|
public void setField(String field) {
|
||||||
this.field = field;
|
this.field = field;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class TestMockServletContext extends MockServletContext {
|
private static class TestMockServletContext extends MockServletContext {
|
||||||
|
|
@ -495,7 +492,6 @@ public class MvcNamespaceTests {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,6 @@
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
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-3.0.xsd">
|
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
|
||||||
|
|
||||||
<mvc:resources mapping="/resources/**" location="/, classpath:/META-INF/" mapping-order="5"/>
|
<mvc:resources mapping="/resources/**" location="/, classpath:/META-INF/" cache-period="3600" order="5"/>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue