Spring源码分析【4】-Spring扫描basePackages注解

 2019-10-17 21:50  阅读(3862)
文章分类:Spring boot

org.springframework.beans.factory.support.DefaultListableBeanFactory

重要数据结构

/** Map of bean definition objects, keyed by bean name */
        private final Map<String, BeanDefinition> beanDefinitionMap = new ConcurrentHashMap<String, BeanDefinition>(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.
ComponentScanAnnotationParser.parse

20191017100203\_1.png

org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan

20191017100203\_2.png

org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents

20191017100203\_3.png

org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.resolveBasePackage

20191017100203\_4.png

org.springframework.util.ClassUtils.convertClassNameToResourcePath

20191017100203\_5.png

getResources

20191017100203\_6.png

getResources

20191017100203\_7.png

findPathMatchingResources

20191017100203\_8.png

determineRootDir

20191017100203\_9.png

回到findPathMatchingResources

20191017100203\_10.png

findPathMatchingResources的result

20191017100203\_11.png

一直退回到findCandidateComponents

20191017100203\_12.png

MetadataReader metadataReader = this.metadataReaderFactory.getMetadataReader(resource);

20191017100203\_13.png

MetadataReader

20191017100203\_14.png

if (isCandidateComponent(metadataReader))

20191017100203\_15.png

ScannedGenericBeanDefinition

20191017100203\_16.png

回到findCandidateComponents

20191017100203\_17.png

return candidates;

20191017100203\_18.png

返回doScan

20191017100203\_19.png

checkCandidate

20191017100203\_20.png

回doScan

20191017100203\_21.png

BeanDefinitionHolder

20191017100203\_22.png

beanDefinitions.add(definitionHolder);

20191017100203\_23.png

registerBeanDefinition

20191017100203\_24.png

registerBeanDefinition

20191017100203\_25.png

oldBeanDefinition = this.beanDefinitionMap.get(beanName);

20191017100203\_26.png

if (hasBeanCreationStarted())

20191017100203\_27.png

this.beanDefinitionMap.put(beanName, beanDefinition);

20191017100203\_28.png

updatedDefinitions

20191017100203\_29.png

doScan return beanDefinitions;

20191017100203\_30.png

org.springframework.context.annotation.ComponentScanAnnotationParser.parse

20191017100203\_31.png

org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass

20191017100203\_32.png

20191017100203\_33.png

parse

20191017100203\_34.png

org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass

20191017100203\_35.png

this.configurationClasses.put(configClass, configClass);

20191017100203\_36.png

回到doProcessConfigurationClass

20191017100203\_37.png

for (SourceClass ifc : sourceClass.getInterfaces()) {

20191017100203\_38.png

doProcessConfigurationClass

// No superclass -> processing is complete

return null;

20191017100203\_39.png

processConfigurationClass

20191017100203\_40.png

org.springframework.context.annotation.ConfigurationClassParser.parse

20191017100203\_41.png

parse

20191017100203\_42.png

org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions

20191017100203\_43.png

alreadyParsed.addAll(configClasses);

20191017100203\_44.png

alreadyParsedClasses

20191017100203\_45.png

20191017100203\_46.png

invokeBeanDefinitionRegistryPostProcessors

20191017100203\_47.png

org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors

20191017100203\_48.png

// Now, invoke the postProcessBeanFactory callback of all processors handled so far.
                invokeBeanFactoryPostProcessors(registryPostProcessors, beanFactory);
                invokeBeanFactoryPostProcessors(regularPostProcessors, beanFactory);

20191017100203\_49.png

postProcessorNames

20191017100203\_50.png

refresh

20191017100203\_51.png


来源:[]()

点赞(0)
版权归原创作者所有,任何形式转载请联系作者; Java 技术驿站 >> Spring源码分析【4】-Spring扫描basePackages注解

相关推荐