Skip to content

Commit 6d4dfed

Browse files
committed
Introduce test for gh-27499 and polish contribution
1 parent 09ef597 commit 6d4dfed

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

spring-aspects/src/test/java/org/springframework/cache/aspectj/JCacheAspectJNamespaceConfigTests.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,13 +22,18 @@
2222

2323
/**
2424
* @author Stephane Nicoll
25+
* @author Sam Brannen
2526
*/
2627
public class JCacheAspectJNamespaceConfigTests extends AbstractJCacheAnnotationTests {
2728

2829
@Override
2930
protected ApplicationContext getApplicationContext() {
30-
return new GenericXmlApplicationContext(
31-
"/org/springframework/cache/config/annotation-jcache-aspectj.xml");
31+
GenericXmlApplicationContext context = new GenericXmlApplicationContext();
32+
// Disallow bean definition overriding to test https://github.com/spring-projects/spring-framework/pull/27499
33+
context.setAllowBeanDefinitionOverriding(false);
34+
context.load("/org/springframework/cache/config/annotation-jcache-aspectj.xml");
35+
context.refresh();
36+
return context;
3237
}
3338

3439
}

spring-context/src/main/java/org/springframework/cache/config/AnnotationDrivenCacheBeanDefinitionParser.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -244,20 +244,20 @@ private static void registerCacheAdvisor(Element element, ParserContext parserCo
244244

245245
private static void registerCacheAspect(Element element, ParserContext parserContext) {
246246
if (!parserContext.getRegistry().containsBeanDefinition(CacheManagementConfigUtils.JCACHE_ASPECT_BEAN_NAME)) {
247-
Object eleSource = parserContext.extractSource(element);
247+
Object source = parserContext.extractSource(element);
248248

249-
BeanDefinition sourceDef = createJCacheOperationSourceBeanDefinition(element, eleSource);
250-
String sourceName = parserContext.getReaderContext().registerWithGeneratedName(sourceDef);
249+
BeanDefinition cacheOperationSourceDef = createJCacheOperationSourceBeanDefinition(element, source);
250+
String cacheOperationSourceName = parserContext.getReaderContext().registerWithGeneratedName(cacheOperationSourceDef);
251251

252-
RootBeanDefinition def = new RootBeanDefinition();
253-
def.setBeanClassName(JCACHE_ASPECT_CLASS_NAME);
254-
def.setFactoryMethodName("aspectOf");
255-
def.getPropertyValues().add("cacheOperationSource", new RuntimeBeanReference(sourceName));
256-
parserContext.getRegistry().registerBeanDefinition(CacheManagementConfigUtils.JCACHE_ASPECT_BEAN_NAME, def);
252+
RootBeanDefinition jcacheAspectDef = new RootBeanDefinition();
253+
jcacheAspectDef.setBeanClassName(JCACHE_ASPECT_CLASS_NAME);
254+
jcacheAspectDef.setFactoryMethodName("aspectOf");
255+
jcacheAspectDef.getPropertyValues().add("cacheOperationSource", new RuntimeBeanReference(cacheOperationSourceName));
256+
parserContext.getRegistry().registerBeanDefinition(CacheManagementConfigUtils.JCACHE_ASPECT_BEAN_NAME, jcacheAspectDef);
257257

258-
CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), eleSource);
259-
compositeDef.addNestedComponent(new BeanComponentDefinition(sourceDef, sourceName));
260-
compositeDef.addNestedComponent(new BeanComponentDefinition(def, CacheManagementConfigUtils.JCACHE_ASPECT_BEAN_NAME));
258+
CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), source);
259+
compositeDef.addNestedComponent(new BeanComponentDefinition(cacheOperationSourceDef, cacheOperationSourceName));
260+
compositeDef.addNestedComponent(new BeanComponentDefinition(jcacheAspectDef, CacheManagementConfigUtils.JCACHE_ASPECT_BEAN_NAME));
261261
parserContext.registerComponent(compositeDef);
262262
}
263263
}

0 commit comments

Comments
 (0)