Change resource handler XML Namespace
This commit changes the way a <mvc:resource-cache> can be configured
with a user defined Cache instance.
Now a reference to a CacheManager Bean and a Cache name must be
provided. This is a more flexible configuration for typical XML setups.
<mvc:resource-cache
cache-manager="resourceCache"
cache-name="test-resource-cache"/>
Issue: SPR-12129
This commit is contained in:
@@ -181,10 +181,12 @@ class ResourcesBeanDefinitionParser implements BeanDefinitionParser {
|
||||
cachingTransformerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
|
||||
cachingTransformerDef.setConstructorArgumentValues(cavs);
|
||||
|
||||
String cacheBeanName = resourceCacheElement.getAttribute("cache");
|
||||
if (StringUtils.hasText(cacheBeanName)) {
|
||||
RuntimeBeanReference cacheRef = new RuntimeBeanReference(cacheBeanName);
|
||||
cavs.addIndexedArgumentValue(0, cacheRef);
|
||||
String cacheManagerName = resourceCacheElement.getAttribute("cache-manager");
|
||||
String cacheName = resourceCacheElement.getAttribute("cache-name");
|
||||
if (StringUtils.hasText(cacheManagerName) && StringUtils.hasText(cacheName)) {
|
||||
RuntimeBeanReference cacheManagerRef = new RuntimeBeanReference(cacheManagerName);
|
||||
cavs.addIndexedArgumentValue(0, cacheManagerRef);
|
||||
cavs.addIndexedArgumentValue(1, cacheName);
|
||||
}
|
||||
else {
|
||||
ConstructorArgumentValues cacheCavs = new ConstructorArgumentValues();
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.web.servlet.resource;
|
||||
|
||||
import org.springframework.cache.Cache;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -40,6 +41,9 @@ public class CachingResourceResolver extends AbstractResourceResolver {
|
||||
|
||||
private final Cache cache;
|
||||
|
||||
public CachingResourceResolver(CacheManager cacheManager, String cacheName) {
|
||||
this(cacheManager.getCache(cacheName));
|
||||
}
|
||||
|
||||
public CachingResourceResolver(Cache cache) {
|
||||
Assert.notNull(cache, "'cache' is required");
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.web.servlet.resource;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.cache.Cache;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -40,6 +41,9 @@ public class CachingResourceTransformer implements ResourceTransformer {
|
||||
|
||||
private final Cache cache;
|
||||
|
||||
public CachingResourceTransformer(CacheManager cacheManager, String cacheName) {
|
||||
this(cacheManager.getCache(cacheName));
|
||||
}
|
||||
|
||||
public CachingResourceTransformer(Cache cache) {
|
||||
Assert.notNull(cache, "'cache' is required");
|
||||
|
||||
@@ -342,10 +342,12 @@
|
||||
<xsd:annotation>
|
||||
<xsd:documentation source="org.springframework.web.servlet.resource.CachingResourceResolver"><![CDATA[
|
||||
A ResourceResolver that resolves resources from a Cache or otherwise delegates to the resolver chain
|
||||
and saves the result in the cache. Can use a custom Cache if provided as a bean reference in the "cache" attribute.
|
||||
and saves the result in the cache. Can use a custom Cache if a CacheManager is provided as a bean reference
|
||||
in the "cache-manager" attribute, and the cache name provided in the "cache-name" attribute.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:attribute name="cache" type="xsd:string" use="optional"/>
|
||||
<xsd:attribute name="cache-manager" type="xsd:string" use="optional"/>
|
||||
<xsd:attribute name="cache-name" type="xsd:string" use="optional"/>
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="content-version-strategy">
|
||||
|
||||
Reference in New Issue
Block a user