Introduce test for gh-27499 and polish contribution
This commit is contained in:
parent
50ccb1bfcd
commit
5bd90538b3
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -22,13 +22,18 @@ import org.springframework.contextsupport.testfixture.jcache.AbstractJCacheAnnot
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
|
* @author Sam Brannen
|
||||||
*/
|
*/
|
||||||
public class JCacheAspectJNamespaceConfigTests extends AbstractJCacheAnnotationTests {
|
public class JCacheAspectJNamespaceConfigTests extends AbstractJCacheAnnotationTests {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ApplicationContext getApplicationContext() {
|
protected ApplicationContext getApplicationContext() {
|
||||||
return new GenericXmlApplicationContext(
|
GenericXmlApplicationContext context = new GenericXmlApplicationContext();
|
||||||
"/org/springframework/cache/config/annotation-jcache-aspectj.xml");
|
// Disallow bean definition overriding to test https://github.com/spring-projects/spring-framework/pull/27499
|
||||||
|
context.setAllowBeanDefinitionOverriding(false);
|
||||||
|
context.load("/org/springframework/cache/config/annotation-jcache-aspectj.xml");
|
||||||
|
context.refresh();
|
||||||
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2018 the original author or authors.
|
* Copyright 2002-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -244,20 +244,20 @@ class AnnotationDrivenCacheBeanDefinitionParser implements BeanDefinitionParser
|
||||||
|
|
||||||
private static void registerCacheAspect(Element element, ParserContext parserContext) {
|
private static void registerCacheAspect(Element element, ParserContext parserContext) {
|
||||||
if (!parserContext.getRegistry().containsBeanDefinition(CacheManagementConfigUtils.JCACHE_ASPECT_BEAN_NAME)) {
|
if (!parserContext.getRegistry().containsBeanDefinition(CacheManagementConfigUtils.JCACHE_ASPECT_BEAN_NAME)) {
|
||||||
Object eleSource = parserContext.extractSource(element);
|
Object source = parserContext.extractSource(element);
|
||||||
|
|
||||||
BeanDefinition sourceDef = createJCacheOperationSourceBeanDefinition(element, eleSource);
|
BeanDefinition cacheOperationSourceDef = createJCacheOperationSourceBeanDefinition(element, source);
|
||||||
String sourceName = parserContext.getReaderContext().registerWithGeneratedName(sourceDef);
|
String cacheOperationSourceName = parserContext.getReaderContext().registerWithGeneratedName(cacheOperationSourceDef);
|
||||||
|
|
||||||
RootBeanDefinition def = new RootBeanDefinition();
|
RootBeanDefinition jcacheAspectDef = new RootBeanDefinition();
|
||||||
def.setBeanClassName(JCACHE_ASPECT_CLASS_NAME);
|
jcacheAspectDef.setBeanClassName(JCACHE_ASPECT_CLASS_NAME);
|
||||||
def.setFactoryMethodName("aspectOf");
|
jcacheAspectDef.setFactoryMethodName("aspectOf");
|
||||||
def.getPropertyValues().add("cacheOperationSource", new RuntimeBeanReference(sourceName));
|
jcacheAspectDef.getPropertyValues().add("cacheOperationSource", new RuntimeBeanReference(cacheOperationSourceName));
|
||||||
parserContext.getRegistry().registerBeanDefinition(CacheManagementConfigUtils.JCACHE_ASPECT_BEAN_NAME, def);
|
parserContext.getRegistry().registerBeanDefinition(CacheManagementConfigUtils.JCACHE_ASPECT_BEAN_NAME, jcacheAspectDef);
|
||||||
|
|
||||||
CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), eleSource);
|
CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), source);
|
||||||
compositeDef.addNestedComponent(new BeanComponentDefinition(sourceDef, sourceName));
|
compositeDef.addNestedComponent(new BeanComponentDefinition(cacheOperationSourceDef, cacheOperationSourceName));
|
||||||
compositeDef.addNestedComponent(new BeanComponentDefinition(def, CacheManagementConfigUtils.JCACHE_ASPECT_BEAN_NAME));
|
compositeDef.addNestedComponent(new BeanComponentDefinition(jcacheAspectDef, CacheManagementConfigUtils.JCACHE_ASPECT_BEAN_NAME));
|
||||||
parserContext.registerComponent(compositeDef);
|
parserContext.registerComponent(compositeDef);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue