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:
Brian Clozel
2014-08-29 18:51:40 +02:00
parent 4df05d1f98
commit 76c46fdbe3
6 changed files with 37 additions and 14 deletions

View File

@@ -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();

View File

@@ -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");

View File

@@ -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");