Add missing cache-resolver attribute

Prior to this commit, CacheResolver could not be configured through
the XML namespace (i.e. cache:annotation-driven). This is now the
case.

Issue: SPR-11490
This commit is contained in:
Stephane Nicoll
2014-05-21 08:32:46 +02:00
parent 1338d46a6e
commit 9952973e01
10 changed files with 174 additions and 17 deletions

View File

@@ -28,6 +28,7 @@ import org.springframework.context.support.GenericXmlApplicationContext;
/**
* @author Costin Leau
* @author Chris Beams
* @author Stephane Nicoll
*/
public class AnnotationNamespaceDrivenTests extends AbstractAnnotationTests {
@@ -44,6 +45,26 @@ public class AnnotationNamespaceDrivenTests extends AbstractAnnotationTests {
assertSame(ctx.getBean("keyGenerator"), ci.getKeyGenerator());
}
@Test
public void cacheResolver() {
ConfigurableApplicationContext context = new GenericXmlApplicationContext(
"/org/springframework/cache/config/annotationDrivenCacheNamespace-resolver.xml");
CacheInterceptor ci = context.getBean(CacheInterceptor.class);
assertSame(context.getBean("cacheResolver"), ci.getCacheResolver());
context.close();
}
@Test
public void bothSetOnlyResolverIsUsed() {
ConfigurableApplicationContext context = new GenericXmlApplicationContext(
"/org/springframework/cache/config/annotationDrivenCacheNamespace-manager-resolver.xml");
CacheInterceptor ci = context.getBean(CacheInterceptor.class);
assertSame(context.getBean("cacheResolver"), ci.getCacheResolver());
context.close();
}
@Test
public void testCacheErrorHandler() {
CacheInterceptor ci = ctx.getBean("org.springframework.cache.interceptor.CacheInterceptor#0",

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">
<cache:annotation-driven cache-manager="customCacheManager"
cache-resolver="cacheResolver"/>
<bean id="customCacheManager" class="org.springframework.cache.support.SimpleCacheManager">
<property name="caches">
<set>
<bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean" p:name="default"/>
</set>
</property>
</bean>
<bean id="cacheResolver" class="org.springframework.cache.interceptor.SimpleCacheResolver">
<property name="cacheManager" ref="customCacheManager"/>
</bean>
</beans>

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">
<cache:annotation-driven cache-resolver="cacheResolver"/>
<bean id="cacheResolver" class="org.springframework.cache.interceptor.SimpleCacheResolver">
<property name="cacheManager">
<bean class="org.springframework.cache.support.SimpleCacheManager">
<property name="caches">
<set>
<bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean"
p:name="default"/>
</set>
</property>
</bean>
</property>
</bean>
</beans>