spring源码分析详解
2020-10-16 10:00:41 0 举报
AI智能生成
spring注解源码分析,学习交流
作者其他创作
大纲/内容
spring源码分析详解
AnnotationConfigApplicationContext
this()
new AnnotatedBeanDefinitionReader
new ConditionEvaluator
AnnotationConfigUtils.registerAnnotationConfigProcessors
unwrapDefaultListableBeanFactory(registry)
ContextAnnotationAutowireCandidateResolver
registry.containsBeanDefinition
new RootBeanDefinition(ConfigurationClassPostProcessor.class)
ConfigurationClassPostProcessor.class
processConfigBeanDefinitions(registry);
registerPostProcessor
setRole
DefaultListableBeanFactory#registerBeanDefinition
validate()
prepareMethodOverrides
DefaultListableBeanFactory#getBeanDefinition
BeanDefinitionHolder
new ClassPathBeanDefinitionScanner
this()#ClassPathBeanDefinitionScanner
register(annotatedClasses)
registerBean
doRegisterBean
new AnnotatedGenericBeanDefinition
shouldSkip
resolveScopeMetadata
generateBeanName
AnnotationConfigUtils.processCommonDefinitionAnnotations(abd)
refresh()
prepareRefresh();
ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory();
prepareBeanFactory(beanFactory);
postProcessBeanFactory(beanFactory);
invokeBeanFactoryPostProcessors(beanFactory);
PostProcessorRegistrationDelegate
BeanDefinitionRegistry
regularPostProcessors
registryProcessors
currentRegistryProcessors
getBeanNamesForType
BeanDefinitionRegistryPostProcessor.class
postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry)
registry.getBeanDefinitionNames();
registry.getBeanDefinition(beanName);
configCandidates.isEmpty()
sbr.getSingleton(CONFIGURATION_BEAN_NAME_GENERATOR)
parser
candidates
alreadyParsed
do {}
parser.parse(candidates);
deferredImportSelectors
ConfigurationClass
existingClass
SourceClass
do{}while()
componentScans
scannedBeanDefinitions
for (BeanDefinitionHolder holder : scannedBeanDefinitions)
importResource
beanMethods
sourceClass.getSuperClass();
processDeferredImportSelectors();
deferredImports.sort(DEFERRED_IMPORT_COMPARATOR);
DeferredImportSelectorGrouping
processImports
importStack.push(configClass);
importCandidates
candidate.isAssignable(ImportSelector.class)
ImportSelector
(this.deferredImportSelectors != null && selector instanceof DeferredImportSelector)
importSourceClasses
candidate.isAssignable(ImportBeanDefinitionRegistrar.class)
addImportBeanDefinitionRegistrar
this.importStack.pop();
parser.validate();
this.reader.loadBeanDefinitions(configClasses);
alreadyParsed.addAll(configClasses);
candidates.clear();
if (registry.getBeanDefinitionCount() > candidateNames.length)
newCandidateNames
oldCandidateNames
alreadyParsedClasses
while (!candidates.isEmpty());
registryProcessors.addAll(currentRegistryProcessors);
currentRegistryProcessors.clear();
registerBeanPostProcessors(beanFactory);
int beanProcessorTargetCount = beanFactory.getBeanPostProcessorCount() + 1 + postProcessorNames.length;
priorityOrderedPostProcessors
internalPostProcessors
orderedPostProcessorNames
nonOrderedPostProcessorNames
for (String ppName : postProcessorNames)
priorityOrderedPostProcessors.add(pp);
beanFactory.addBeanPostProcessor(new ApplicationListenerDetector(applicationContext));
initMessageSource();
initApplicationEventMulticaster();
getApplicationListeners()
getApplicationEventMulticaster().addApplicationListener(listener);
getApplicationEventMulticaster().addApplicationListenerBean(listenerBeanName);
Set<ApplicationEvent> earlyEventsToProcess
getApplicationEventMulticaster().multicastEvent(earlyEvent);
onRefresh();
registerListeners();
finishBeanFactoryInitialization(beanFactory);
beanFactory.freezeConfiguration();
beanFactory.preInstantiateSingletons();
getMergedLocalBeanDefinition(beanName);
getBean(beanName);
transformedBeanName(name);
getSingleton(beanName);
this.singletonObjects.get(beanName);
if (singletonObject == null && isSingletonCurrentlyInCreation(beanName))
synchronized (this.singletonObjects)
singletonObject =this.earlySingletonObjects.get(beanName);
if (singletonObject == null && allowEarlyReference)
singletonFactory = this.singletonFactories.get(beanName);
if (singletonFactory != null)
singletonObject = singletonFactory.getObject();
mbdToUse.setBeanClass(resolvedClass);
mbdToUse.prepareMethodOverrides();
if (mbd.isSingleton())
this.factoryBeanInstanceCache.remove(beanName);
if (instanceWrapper == null)
if (beanClass != null && !Modifier.isPublic(beanClass.getModifiers()) && !mbd.isNonPublicAccessAllowed())
mbd.getInstanceSupplier();
boolean earlySingletonExposure = (mbd.isSingleton() && this.allowCircularReferences &&\t\t\t\tisSingletonCurrentlyInCreation(beanName));
addSingletonFactory
boolean continueWithPropertyPopulation = true;
getBeanPostProcessors()
InstantiationAwareBeanPostProcessor
if (mbd.getResolvedAutowireMode() == AUTOWIRE_BY_NAME || mbd.getResolvedAutowireMode() == AUTOWIRE_BY_TYPE)
PropertyValues pvs = (mbd.hasPropertyValues() ? mbd.getPropertyValues() : null);
hasInstantiationAwareBeanPostProcessors();
needsDepCheck
BeanNameAware
BeanClassLoaderAware
BeanFactoryAware
getCachedObjectForFactoryBean(beanName);
this.singletonFactories.remove(beanName);
if (sharedInstance != null && args == null)
else { isPrototypeCurrentlyInCreation(beanName) }
getParentBeanFactory();
if (parentBeanFactory != null && !containsBeanDefinition(beanName))
originalBeanName(name);
if (parentBeanFactory instanceof AbstractBeanFactory)
markBeanAsCreated(beanName);
mbd.getDependsOn();
getBean(dep);
Object singletonObject = this.singletonObjects.get(beanName);
beforeSingletonCreation(beanName);
singletonObject = this.singletonObjects.get(beanName);
afterSingletonCreation(beanName);
if (newSingleton)
destroySingleton(beanName);
else if (mbd.isPrototype())
beforePrototypeCreation(beanName);
afterPrototypeCreation(beanName);
finishRefresh();
destroyBeans();
cancelRefresh(ex);
resetCommonCaches();
0 条评论
回复 删除
下一页