Browse Source

Parse cache:annotation-driven key-generator attribute

Prior to this change, the spring-cache XSD allowed a 'key-generator'
attribute, but it was not actually parsed by AnnotationDrivenCacheBDP.

This commit adds the parsing logic as originally intended and the test
to prove it.

Issue: SPR-8939
pull/11/head
Costin Leau 14 years ago committed by Chris Beams
parent
commit
c39a14a130
  1. 8
      org.springframework.aspects/src/test/java/org/springframework/cache/aspectj/AspectJAnnotationTest.java
  2. 23
      org.springframework.aspects/src/test/java/org/springframework/cache/config/SomeKeyGenerator.java
  3. 12
      org.springframework.aspects/src/test/java/org/springframework/cache/config/annotation-cache-aspectj.xml
  4. 4
      org.springframework.context/src/main/java/org/springframework/cache/config/AnnotationDrivenCacheBeanDefinitionParser.java

8
org.springframework.aspects/src/test/java/org/springframework/cache/aspectj/AspectJAnnotationTest.java vendored

@ -16,6 +16,8 @@
package org.springframework.cache.aspectj; package org.springframework.cache.aspectj;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext; import org.springframework.context.support.GenericXmlApplicationContext;
@ -30,4 +32,10 @@ public class AspectJAnnotationTest extends AbstractAnnotationTest {
protected ApplicationContext getApplicationContext() { protected ApplicationContext getApplicationContext() {
return new GenericXmlApplicationContext("/org/springframework/cache/config/annotation-cache-aspectj.xml"); return new GenericXmlApplicationContext("/org/springframework/cache/config/annotation-cache-aspectj.xml");
} }
@Test
public void testKeyStrategy() throws Exception {
AnnotationCacheAspect aspect = ctx.getBean("org.springframework.cache.config.internalCacheAspect", AnnotationCacheAspect.class);
Assert.assertSame(ctx.getBean("keyGenerator"), aspect.getKeyGenerator());
}
} }

23
org.springframework.aspects/src/test/java/org/springframework/cache/config/SomeKeyGenerator.java vendored

@ -0,0 +1,23 @@
/*
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cache.config;
import org.springframework.cache.interceptor.DefaultKeyGenerator;
public class SomeKeyGenerator extends DefaultKeyGenerator {
}

12
org.springframework.aspects/src/test/java/org/springframework/cache/config/annotation-cache-aspectj.xml vendored

@ -14,7 +14,7 @@
<aop:config> <aop:config>
<aop:advisor advice-ref="debugInterceptor" pointcut="execution(* *..CacheableService.*(..))" order="1"/> <aop:advisor advice-ref="debugInterceptor" pointcut="execution(* *..CacheableService.*(..))" order="1"/>
</aop:config> </aop:config>
<bean id="cacheAspect" class="org.springframework.cache.aspectj.AnnotationCacheAspect" factory-method="aspectOf"> <bean id="cacheAspect" class="org.springframework.cache.aspectj.AnnotationCacheAspect" factory-method="aspectOf">
<property name="cacheManager" ref="cacheManager"/> <property name="cacheManager" ref="cacheManager"/>
<property name="cacheOperationSources" ref="annotationSource"/> <property name="cacheOperationSources" ref="annotationSource"/>
@ -22,8 +22,10 @@
<bean id="annotationSource" class="org.springframework.cache.annotation.AnnotationCacheOperationSource"/> <bean id="annotationSource" class="org.springframework.cache.annotation.AnnotationCacheOperationSource"/>
--> -->
<cache:annotation-driven mode="aspectj"/> <cache:annotation-driven mode="aspectj" key-generator="keyGenerator"/>
<bean id="keyGenerator" class="org.springframework.cache.config.SomeKeyGenerator" />
<bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager"> <bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">
<property name="caches"> <property name="caches">
@ -36,8 +38,8 @@
</bean> </bean>
<bean id="debugInterceptor" class="org.springframework.aop.interceptor.DebugInterceptor"/> <bean id="debugInterceptor" class="org.springframework.aop.interceptor.DebugInterceptor"/>
<bean id="service" class="org.springframework.cache.config.DefaultCacheableService"/> <bean id="service" class="org.springframework.cache.config.DefaultCacheableService"/>
<bean id="classService" class="org.springframework.cache.config.AnnotatedClassCacheableService"/> <bean id="classService" class="org.springframework.cache.config.AnnotatedClassCacheableService"/>
</beans> </beans>

4
org.springframework.context/src/main/java/org/springframework/cache/config/AnnotationDrivenCacheBeanDefinitionParser.java vendored

@ -76,7 +76,8 @@ class AnnotationDrivenCacheBeanDefinitionParser implements BeanDefinitionParser
* Registers a * Registers a
* <pre> * <pre>
* <bean id="cacheAspect" class="org.springframework.cache.aspectj.AnnotationCacheAspect" factory-method="aspectOf"> * <bean id="cacheAspect" class="org.springframework.cache.aspectj.AnnotationCacheAspect" factory-method="aspectOf">
* <property name="cacheManagerBeanName" value="cacheManager"/> * <property name="cacheManager" ref="cacheManager"/>
* <property name="keyGenerator" ref="keyGenerator"/>
* </bean> * </bean>
* *
* </pre> * </pre>
@ -89,6 +90,7 @@ class AnnotationDrivenCacheBeanDefinitionParser implements BeanDefinitionParser
def.setBeanClassName(CACHE_ASPECT_CLASS_NAME); def.setBeanClassName(CACHE_ASPECT_CLASS_NAME);
def.setFactoryMethodName("aspectOf"); def.setFactoryMethodName("aspectOf");
parseCacheManagerProperty(element, def); parseCacheManagerProperty(element, def);
CacheNamespaceHandler.parseKeyGenerator(element, def);
parserContext.registerBeanComponent(new BeanComponentDefinition(def, CACHE_ASPECT_BEAN_NAME)); parserContext.registerBeanComponent(new BeanComponentDefinition(def, CACHE_ASPECT_BEAN_NAME));
} }
} }

Loading…
Cancel
Save