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
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.cache.aspectj;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.GenericXmlApplicationContext;
|
||||
|
||||
@@ -30,4 +32,10 @@ public class AspectJAnnotationTest extends AbstractAnnotationTest {
|
||||
protected ApplicationContext getApplicationContext() {
|
||||
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
Normal file
23
org.springframework.aspects/src/test/java/org/springframework/cache/config/SomeKeyGenerator.java
vendored
Normal file
@@ -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 {
|
||||
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
<aop:config>
|
||||
<aop:advisor advice-ref="debugInterceptor" pointcut="execution(* *..CacheableService.*(..))" order="1"/>
|
||||
</aop:config>
|
||||
|
||||
|
||||
<bean id="cacheAspect" class="org.springframework.cache.aspectj.AnnotationCacheAspect" factory-method="aspectOf">
|
||||
<property name="cacheManager" ref="cacheManager"/>
|
||||
<property name="cacheOperationSources" ref="annotationSource"/>
|
||||
@@ -22,8 +22,10 @@
|
||||
|
||||
<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">
|
||||
<property name="caches">
|
||||
@@ -36,8 +38,8 @@
|
||||
</bean>
|
||||
|
||||
<bean id="debugInterceptor" class="org.springframework.aop.interceptor.DebugInterceptor"/>
|
||||
|
||||
|
||||
<bean id="service" class="org.springframework.cache.config.DefaultCacheableService"/>
|
||||
<bean id="classService" class="org.springframework.cache.config.AnnotatedClassCacheableService"/>
|
||||
|
||||
</beans>
|
||||
</beans>
|
||||
|
||||
@@ -76,7 +76,8 @@ class AnnotationDrivenCacheBeanDefinitionParser implements BeanDefinitionParser
|
||||
* Registers a
|
||||
* <pre>
|
||||
* <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>
|
||||
*
|
||||
* </pre>
|
||||
@@ -89,6 +90,7 @@ class AnnotationDrivenCacheBeanDefinitionParser implements BeanDefinitionParser
|
||||
def.setBeanClassName(CACHE_ASPECT_CLASS_NAME);
|
||||
def.setFactoryMethodName("aspectOf");
|
||||
parseCacheManagerProperty(element, def);
|
||||
CacheNamespaceHandler.parseKeyGenerator(element, def);
|
||||
parserContext.registerBeanComponent(new BeanComponentDefinition(def, CACHE_ASPECT_BEAN_NAME));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user