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");
|
||||
|
||||
Reference in New Issue
Block a user