@@ -133,7 +133,7 @@ public int compare(DeferredImportSelectorHolder o1, DeferredImportSelectorHolder
133
133
134
134
private final ImportStack importStack = new ImportStack ();
135
135
136
- private final List <DeferredImportSelectorHolder > deferredImportSelectors = new LinkedList < DeferredImportSelectorHolder >() ;
136
+ private List <DeferredImportSelectorHolder > deferredImportSelectors ;
137
137
138
138
139
139
/**
@@ -156,6 +156,8 @@ public ConfigurationClassParser(MetadataReaderFactory metadataReaderFactory,
156
156
157
157
158
158
public void parse (Set <BeanDefinitionHolder > configCandidates ) {
159
+ this .deferredImportSelectors = new LinkedList <DeferredImportSelectorHolder >();
160
+
159
161
for (BeanDefinitionHolder holder : configCandidates ) {
160
162
BeanDefinition bd = holder .getBeanDefinition ();
161
163
try {
@@ -177,6 +179,7 @@ else if (bd instanceof AbstractBeanDefinition && ((AbstractBeanDefinition) bd).h
177
179
"Failed to parse configuration class [" + bd .getBeanClassName () + "]" , ex );
178
180
}
179
181
}
182
+
180
183
processDeferredImportSelectors ();
181
184
}
182
185
@@ -269,7 +272,7 @@ protected final SourceClass doProcessConfigurationClass(ConfigurationClass confi
269
272
}
270
273
271
274
// Process any @Import annotations
272
- processImports (configClass , sourceClass , getImports (sourceClass ), true , false );
275
+ processImports (configClass , sourceClass , getImports (sourceClass ), true );
273
276
274
277
// Process any @ImportResource annotations
275
278
if (sourceClass .getMetadata ().isAnnotated (ImportResource .class .getName ())) {
@@ -427,12 +430,15 @@ private void collectImports(SourceClass sourceClass, Set<SourceClass> imports, S
427
430
}
428
431
429
432
private void processDeferredImportSelectors () {
430
- Collections .sort (this .deferredImportSelectors , DEFERRED_IMPORT_COMPARATOR );
431
- for (DeferredImportSelectorHolder deferredImport : this .deferredImportSelectors ) {
433
+ List <DeferredImportSelectorHolder > deferredImports = this .deferredImportSelectors ;
434
+ this .deferredImportSelectors = null ;
435
+ Collections .sort (deferredImports , DEFERRED_IMPORT_COMPARATOR );
436
+
437
+ for (DeferredImportSelectorHolder deferredImport : deferredImports ) {
432
438
ConfigurationClass configClass = deferredImport .getConfigurationClass ();
433
439
try {
434
440
String [] imports = deferredImport .getImportSelector ().selectImports (configClass .getMetadata ());
435
- processImports (configClass , asSourceClass (configClass ), asSourceClasses (imports ), false , true );
441
+ processImports (configClass , asSourceClass (configClass ), asSourceClasses (imports ), false );
436
442
}
437
443
catch (BeanDefinitionStoreException ex ) {
438
444
throw ex ;
@@ -442,11 +448,10 @@ private void processDeferredImportSelectors() {
442
448
configClass .getMetadata ().getClassName () + "]" , ex );
443
449
}
444
450
}
445
- this .deferredImportSelectors .clear ();
446
451
}
447
452
448
453
private void processImports (ConfigurationClass configClass , SourceClass currentSourceClass ,
449
- Collection <SourceClass > importCandidates , boolean checkForCircularImports , boolean deferred ) throws IOException {
454
+ Collection <SourceClass > importCandidates , boolean checkForCircularImports ) throws IOException {
450
455
451
456
if (importCandidates .isEmpty ()) {
452
457
return ;
@@ -464,14 +469,14 @@ private void processImports(ConfigurationClass configClass, SourceClass currentS
464
469
Class <?> candidateClass = candidate .loadClass ();
465
470
ImportSelector selector = BeanUtils .instantiateClass (candidateClass , ImportSelector .class );
466
471
invokeAwareMethods (selector );
467
- if (! deferred && selector instanceof DeferredImportSelector ) {
472
+ if (this . deferredImportSelectors != null && selector instanceof DeferredImportSelector ) {
468
473
this .deferredImportSelectors .add (
469
474
new DeferredImportSelectorHolder (configClass , (DeferredImportSelector ) selector ));
470
475
}
471
476
else {
472
477
String [] importClassNames = selector .selectImports (currentSourceClass .getMetadata ());
473
478
Collection <SourceClass > importSourceClasses = asSourceClasses (importClassNames );
474
- processImports (configClass , currentSourceClass , importSourceClasses , false , false );
479
+ processImports (configClass , currentSourceClass , importSourceClasses , false );
475
480
}
476
481
}
477
482
else if (candidate .isAssignable (ImportBeanDefinitionRegistrar .class )) {
0 commit comments