36
36
import org .springframework .beans .factory .BeanClassLoaderAware ;
37
37
import org .springframework .beans .factory .BeanDefinitionStoreException ;
38
38
import org .springframework .beans .factory .BeanFactory ;
39
- import org .springframework .beans .factory .BeanFactoryAware ;
40
- import org .springframework .beans .factory .annotation .AutowiredAnnotationBeanPostProcessor ;
41
39
import org .springframework .beans .factory .config .BeanDefinition ;
42
40
import org .springframework .beans .factory .config .BeanDefinitionHolder ;
43
41
import org .springframework .beans .factory .config .BeanFactoryPostProcessor ;
44
- import org .springframework .beans .factory .config .BeanPostProcessor ;
45
42
import org .springframework .beans .factory .config .ConfigurableListableBeanFactory ;
46
43
import org .springframework .beans .factory .config .InstantiationAwareBeanPostProcessorAdapter ;
47
44
import org .springframework .beans .factory .config .SingletonBeanRegistry ;
53
50
import org .springframework .beans .factory .support .BeanDefinitionRegistry ;
54
51
import org .springframework .beans .factory .support .BeanDefinitionRegistryPostProcessor ;
55
52
import org .springframework .beans .factory .support .BeanNameGenerator ;
56
- import org .springframework .beans .factory .support .RootBeanDefinition ;
57
53
import org .springframework .context .EnvironmentAware ;
58
54
import org .springframework .context .ResourceLoaderAware ;
59
55
import org .springframework .context .annotation .ConfigurationClassEnhancer .EnhancedConfiguration ;
91
87
public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPostProcessor ,
92
88
PriorityOrdered , ResourceLoaderAware , BeanClassLoaderAware , EnvironmentAware {
93
89
94
- private static final String IMPORT_AWARE_PROCESSOR_BEAN_NAME =
95
- ConfigurationClassPostProcessor .class .getName () + ".importAwareProcessor" ;
96
-
97
90
private static final String IMPORT_REGISTRY_BEAN_NAME =
98
91
ConfigurationClassPostProcessor .class .getName () + ".importRegistry" ;
99
92
100
- private static final String ENHANCED_CONFIGURATION_PROCESSOR_BEAN_NAME =
101
- ConfigurationClassPostProcessor .class .getName () + ".enhancedConfigurationProcessor" ;
102
-
103
93
104
94
private final Log logger = LogFactory .getLog (getClass ());
105
95
@@ -224,14 +214,6 @@ public void setBeanClassLoader(ClassLoader beanClassLoader) {
224
214
*/
225
215
@ Override
226
216
public void postProcessBeanDefinitionRegistry (BeanDefinitionRegistry registry ) {
227
- RootBeanDefinition iabpp = new RootBeanDefinition (ImportAwareBeanPostProcessor .class );
228
- iabpp .setRole (BeanDefinition .ROLE_INFRASTRUCTURE );
229
- registry .registerBeanDefinition (IMPORT_AWARE_PROCESSOR_BEAN_NAME , iabpp );
230
-
231
- RootBeanDefinition ecbpp = new RootBeanDefinition (EnhancedConfigurationBeanPostProcessor .class );
232
- ecbpp .setRole (BeanDefinition .ROLE_INFRASTRUCTURE );
233
- registry .registerBeanDefinition (ENHANCED_CONFIGURATION_PROCESSOR_BEAN_NAME , ecbpp );
234
-
235
217
int registryId = System .identityHashCode (registry );
236
218
if (this .registriesPostProcessed .contains (registryId )) {
237
219
throw new IllegalStateException (
@@ -263,7 +245,9 @@ public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
263
245
// Simply call processConfigurationClasses lazily at this point then.
264
246
processConfigBeanDefinitions ((BeanDefinitionRegistry ) beanFactory );
265
247
}
248
+
266
249
enhanceConfigurationClasses (beanFactory );
250
+ beanFactory .addBeanPostProcessor (new ImportAwareBeanPostProcessor (beanFactory ));
267
251
}
268
252
269
253
/**
@@ -422,18 +406,22 @@ else if (logger.isWarnEnabled() && beanFactory.containsSingleton(beanName)) {
422
406
}
423
407
424
408
425
- private static class ImportAwareBeanPostProcessor implements BeanPostProcessor , BeanFactoryAware , PriorityOrdered {
409
+ private static class ImportAwareBeanPostProcessor extends InstantiationAwareBeanPostProcessorAdapter {
426
410
427
- private BeanFactory beanFactory ;
411
+ private final BeanFactory beanFactory ;
428
412
429
- @ Override
430
- public void setBeanFactory (BeanFactory beanFactory ) {
413
+ public ImportAwareBeanPostProcessor (BeanFactory beanFactory ) {
431
414
this .beanFactory = beanFactory ;
432
415
}
433
416
434
417
@ Override
435
- public int getOrder () {
436
- return Ordered .HIGHEST_PRECEDENCE ;
418
+ public PropertyValues postProcessPropertyValues (PropertyValues pvs , PropertyDescriptor [] pds , Object bean , String beanName ) {
419
+ // Inject the BeanFactory before AutowiredAnnotationBeanPostProcessor's
420
+ // postProcessPropertyValues method attempts to autowire other configuration beans.
421
+ if (bean instanceof EnhancedConfiguration ) {
422
+ ((EnhancedConfiguration ) bean ).setBeanFactory (this .beanFactory );
423
+ }
424
+ return pvs ;
437
425
}
438
426
439
427
@ Override
@@ -454,36 +442,4 @@ public Object postProcessAfterInitialization(Object bean, String beanName) {
454
442
}
455
443
}
456
444
457
-
458
- /**
459
- * {@link InstantiationAwareBeanPostProcessorAdapter} that ensures
460
- * {@link EnhancedConfiguration} beans are injected with the {@link BeanFactory}
461
- * before the {@link AutowiredAnnotationBeanPostProcessor} runs (SPR-10668).
462
- */
463
- private static class EnhancedConfigurationBeanPostProcessor extends InstantiationAwareBeanPostProcessorAdapter
464
- implements PriorityOrdered , BeanFactoryAware {
465
-
466
- private BeanFactory beanFactory ;
467
-
468
- @ Override
469
- public int getOrder () {
470
- return Ordered .HIGHEST_PRECEDENCE ;
471
- }
472
-
473
- @ Override
474
- public void setBeanFactory (BeanFactory beanFactory ) {
475
- this .beanFactory = beanFactory ;
476
- }
477
-
478
- @ Override
479
- public PropertyValues postProcessPropertyValues (PropertyValues pvs , PropertyDescriptor [] pds , Object bean , String beanName ) {
480
- // Inject the BeanFactory before AutowiredAnnotationBeanPostProcessor's
481
- // postProcessPropertyValues method attempts to auto-wire other configuration beans.
482
- if (bean instanceof EnhancedConfiguration ) {
483
- ((EnhancedConfiguration ) bean ).setBeanFactory (this .beanFactory );
484
- }
485
- return pvs ;
486
- }
487
- }
488
-
489
445
}
0 commit comments