重点方法:
invokeBeanFactoryPostProcessors(beanFactory)
1.registryProcessor.postProcessBeanDefinitionRegistry(registry) # 执行各种BeanFactoryPostProcessors,其中就有 ConfigurationClassPostProcessor
- 获取含有@ConfigurationConfiguration注解的类ClassUtils.checkConfigurationClassCandidate(beanDef, this.metadataReaderFactory)
--> Map, Object> config = metadata.getAnnotationAttributes(Configuration.class.getName())
-->configCandidates.add(new BeanDefinitionHolder(beanDef, beanName))
- 处理 (ConfigurationClassParser)parser.parse(candidates)
-->parse(((AnnotatedBeanDefinition) bd).getMetadata(), holder.getBeanName())
-->processConfigurationClass(new ConfigurationClass(metadata, beanName), DEFAULT_EXCLUSION_FILTER)
-->doProcessConfigurationClass(configClass, sourceClass, filter)
- processPropertySource(propertySource)-->Process any @PropertySource annotations
Set<BeanDefinitionHolder> scannedBeanDefinitions =
this.componentScanParser.parse(componentScan, sourceClass.getMetadata().getClassName())-->Process any @ComponentScan annotations
processImports(configClass, sourceClass, getImports(sourceClass), filter, true) -->Process any @Import annotations
this.environment.resolveRequiredPlaceholders(resource)-->Process any @ImportResource annotations
- 在处理@Import注解时
this.deferredImportSelectorHandler.handle(configClass, (DeferredImportSelector) selector) -->Candidate class is an ImportSelector -> delegate to it to determine imports
ParserStrategyUtils.instantiateClass(candidateClass, ImportBeanDefinitionRegistrar.class,
this.environment, this.resourceLoader, this.registry)-->Candidate class is an ImportBeanDefinitionRegistrar , delegate to it to register additional bean definitions
this.importStack.registerImport(
currentSourceClass.getMetadata(), candidate.getMetadata().getClassName());
processConfigurationClass(candidate.asConfigClass(configClass), exclusionFilter)-->process it as an @Configuration class