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

@@ -32,6 +32,8 @@ import org.junit.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.TypeMismatchException;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.cache.concurrent.ConcurrentMapCache;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.core.Ordered;
@@ -350,7 +352,8 @@ public class MvcNamespaceTests {
assertThat(resolvers.get(2), Matchers.instanceOf(PathResourceResolver.class));
CachingResourceResolver cachingResolver = (CachingResourceResolver) resolvers.get(0);
assertThat(cachingResolver.getCache(), Matchers.instanceOf(TestResourceCache.class));
assertThat(cachingResolver.getCache(), Matchers.instanceOf(ConcurrentMapCache.class));
assertEquals("test-resource-cache", cachingResolver.getCache().getName());
VersionResourceResolver versionResolver = (VersionResourceResolver) resolvers.get(1);
assertThat(versionResolver.getStrategyMap().get("/**/*.js"),
@@ -363,6 +366,10 @@ public class MvcNamespaceTests {
assertThat(transformers.get(0), Matchers.instanceOf(CachingResourceTransformer.class));
assertThat(transformers.get(1), Matchers.instanceOf(CssLinkResourceTransformer.class));
assertThat(transformers.get(2), Matchers.instanceOf(AppCacheManifestTransformer.class));
CachingResourceTransformer cachingTransformer = (CachingResourceTransformer) transformers.get(0);
assertThat(cachingTransformer.getCache(), Matchers.instanceOf(ConcurrentMapCache.class));
assertEquals("test-resource-cache", cachingTransformer.getCache().getName());
}
@Test
@@ -869,9 +876,15 @@ public class MvcNamespaceTests {
public static class TestPathHelper extends UrlPathHelper { }
public static class TestResourceCache extends ConcurrentMapCache {
public TestResourceCache(String name) {
super(name);
public static class TestCacheManager implements CacheManager {
@Override
public Cache getCache(String name) {
return new ConcurrentMapCache(name);
}
@Override
public Collection<String> getCacheNames() {
return null;
}
}