Revised test for ImportBeanDefinitionRegistrar double scan
Issue: SPR-12334
(cherry picked from commit 6e5711a)
This commit is contained in:
parent
3106905877
commit
a2731f1a4f
|
|
@ -456,7 +456,8 @@ class ConfigurationClassParser {
|
|||
ImportSelector selector = BeanUtils.instantiateClass(candidateClass, ImportSelector.class);
|
||||
invokeAwareMethods(selector);
|
||||
if (!deferred && selector instanceof DeferredImportSelector) {
|
||||
this.deferredImportSelectors.add(new DeferredImportSelectorHolder(configClass, (DeferredImportSelector) selector));
|
||||
this.deferredImportSelectors.add(
|
||||
new DeferredImportSelectorHolder(configClass, (DeferredImportSelector) selector));
|
||||
}
|
||||
else {
|
||||
String[] importClassNames = selector.selectImports(currentSourceClass.getMetadata());
|
||||
|
|
@ -465,15 +466,19 @@ class ConfigurationClassParser {
|
|||
}
|
||||
}
|
||||
else if (candidate.isAssignable(ImportBeanDefinitionRegistrar.class)) {
|
||||
// Candidate class is an ImportBeanDefinitionRegistrar -> delegate to it to register additional bean definitions
|
||||
// Candidate class is an ImportBeanDefinitionRegistrar ->
|
||||
// delegate to it to register additional bean definitions
|
||||
Class<?> candidateClass = candidate.loadClass();
|
||||
ImportBeanDefinitionRegistrar registrar = BeanUtils.instantiateClass(candidateClass, ImportBeanDefinitionRegistrar.class);
|
||||
ImportBeanDefinitionRegistrar registrar =
|
||||
BeanUtils.instantiateClass(candidateClass, ImportBeanDefinitionRegistrar.class);
|
||||
invokeAwareMethods(registrar);
|
||||
configClass.addImportBeanDefinitionRegistrar(registrar, currentSourceClass.getMetadata());
|
||||
}
|
||||
else {
|
||||
// Candidate class not an ImportSelector or ImportBeanDefinitionRegistrar -> process it as a @Configuration class
|
||||
this.importStack.registerImport(currentSourceClass.getMetadata(), candidate.getMetadata().getClassName());
|
||||
// Candidate class not an ImportSelector or ImportBeanDefinitionRegistrar ->
|
||||
// process it as a @Configuration class
|
||||
this.importStack.registerImport(
|
||||
currentSourceClass.getMetadata(), candidate.getMetadata().getClassName());
|
||||
processConfigurationClass(candidate.asConfigClass(configClass));
|
||||
}
|
||||
}
|
||||
|
|
@ -678,12 +683,12 @@ class ConfigurationClassParser {
|
|||
|
||||
|
||||
/**
|
||||
* Simple wrapper that allows annotated source classes to be dealt with in a uniform
|
||||
* manor, regardless of how they are loaded.
|
||||
* Simple wrapper that allows annotated source classes to be dealt with
|
||||
* in a uniform manner, regardless of how they are loaded.
|
||||
*/
|
||||
private class SourceClass {
|
||||
|
||||
private final Object source; // Class or MetaDataReader
|
||||
private final Object source; // Class or MetadataReader
|
||||
|
||||
private final AnnotationMetadata metadata;
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,8 @@ public class Spr12334Tests {
|
|||
|
||||
@Test
|
||||
public void shouldNotScanTwice() {
|
||||
TestImport.scanned = false;
|
||||
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
context.scan(TestImport.class.getPackage().getName());
|
||||
context.refresh();
|
||||
|
|
@ -53,14 +55,14 @@ public class Spr12334Tests {
|
|||
|
||||
public static class TestImport implements ImportBeanDefinitionRegistrar {
|
||||
|
||||
private boolean scanned = false;
|
||||
private static boolean scanned = false;
|
||||
|
||||
@Override
|
||||
public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) {
|
||||
if (this.scanned) {
|
||||
if (scanned) {
|
||||
throw new IllegalStateException("Already scanned");
|
||||
}
|
||||
this.scanned = true;
|
||||
scanned = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue