org.springframework.beans.factory.support.DefaultListableBeanFactory
重要数据结构
/** Map of bean definition objects, keyed by bean name */
private final Map beanDefinitionMap = new ConcurrentHashMap(256);
RootConfig 代码
@Configuration
@Import(MybatisConfig.class)
@ComponentScan(basePackages = {"com.xxx.*"},
excludeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION, value = EnableWebMvc.class)})
public class RootConfig {
}
org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan
org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents
org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.resolveBasePackage
org.springframework.util.ClassUtils.convertClassNameToResourcePath
getResources
getResources
findPathMatchingResources
determineRootDir
回到findPathMatchingResources
findPathMatchingResources的result
一直退回到findCandidateComponents
MetadataReader metadataReader = this.metadataReaderFactory.getMetadataReader(resource);
MetadataReader
if (isCandidateComponent(metadataReader))
ScannedGenericBeanDefinition
回到findCandidateComponents
return candidates;
返回doScan
checkCandidate
回doScan
BeanDefinitionHolder
beanDefinitions.add(definitionHolder);
registerBeanDefinition
registerBeanDefinition
oldBeanDefinition = this.beanDefinitionMap.get(beanName);
if (hasBeanCreationStarted())
this.beanDefinitionMap.put(beanName, beanDefinition);
updatedDefinitions
doScan return beanDefinitions;
org.springframework.context.annotation.ComponentScanAnnotationParser.parse
org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass
parse
org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass
this.configurationClasses.put(configClass, configClass);
回到doProcessConfigurationClass
for (SourceClass ifc : sourceClass.getInterfaces()) {
doProcessConfigurationClass
// No superclass -> processing is complete
return null;
processConfigurationClass
org.springframework.context.annotation.ConfigurationClassParser.parse
parse
org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions
alreadyParsed.addAll(configClasses);
alreadyParsedClasses
invokeBeanDefinitionRegistryPostProcessors
org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors
// Now, invoke the postProcessBeanFactory callback of all processors handled so far.
invokeBeanFactoryPostProcessors(registryPostProcessors, beanFactory);
invokeBeanFactoryPostProcessors(regularPostProcessors, beanFactory);
postProcessorNames
refresh