ClassPathXmlApplicationContext流程解析
2022-05-19 09:48:48 1 举报
AI智能生成
ClassPathXmlApplicationContext初始化流程思维导图
作者其他创作
大纲/内容
1、prepareRefresh()
initPropertySources()
getEnvironment().validateRequiredProperties()
2、ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory()
AbstractRefreshableApplicationContext.
refreshBeanFactory()
refreshBeanFactory()
hasBeanFactory()
destroyBeans()
closeBeanFactory()
createBeanFactory()
beanFactory.setSerializationId(getId())
customizeBeanFactory(beanFactory)
AbstractXmlApplicationContext.
loadBeanDefinitions(beanFactory)
loadBeanDefinitions(beanFactory)
initBeanDefinitionReader(beanDefinitionReader)
loadBeanDefinitions(beanDefinitionReader)
getConfigResources()
getConfigLocations()
AbstractBeanDefinitionReader.
loadBeanDefinitions(configLocations)
loadBeanDefinitions(configLocations)
getResourceLoader()
((ResourcePatternResolver) resourceLoader).getResources(location)
loadBeanDefinitions(resources)
loadBeanDefinitions(resource)
encodedResource.getResource().getInputStream()
InputSource inputSource = new InputSource(inputStream)
XmlBeanDefinitionReader.
doLoadBeanDefinitions(inputSource, encodedResource.getResource())
doLoadBeanDefinitions(inputSource, encodedResource.getResource())
doLoadDocument(inputSource, resource)
registerBeanDefinitions(doc, resource)
createBeanDefinitionDocumentReader()
documentReader.registerBeanDefinitions(doc, createReaderContext(resource))
DefaultBeanDefinitionDocumentReader.
doRegisterBeanDefinitions(doc.getDocumentElement())
doRegisterBeanDefinitions(doc.getDocumentElement())
createDelegate(getReaderContext(), root, parent)
preProcessXml(root)
parseBeanDefinitions(root, this.delegate)
parseDefaultElement(ele, delegate)
importBeanDefinitionResource(ele)
processAliasRegistration(ele)
processBeanDefinition(ele, delegate)
delegate.parseBeanDefinitionElement
BeanDefinitionParserDelegate.
parseBeanDefinitionElement(ele, null)
parseBeanDefinitionElement(ele, null)
checkNameUniqueness(beanName, aliases, ele)
parseBeanDefinitionElement(ele, beanName, containingBean)
createBeanDefinition(className, parent)
parseBeanDefinitionAttributes(ele, beanName, containingBean, bd)
bd.setDescription(DomUtils.getChildElementValueByTagName(ele, DESCRIPTION_ELEMENT))
parseMetaElements(ele, bd)
parseLookupOverrideSubElements(ele, bd.getMethodOverrides())
parseReplacedMethodSubElements(ele, bd.getMethodOverrides())
parseConstructorArgElements(ele, bd)
parsePropertyElements(ele, bd)
parseQualifierElements(ele, bd)
new BeanDefinitionHolder(beanDefinition, beanName, aliasesArray)
delegate.decorateBeanDefinitionIfRequired(ele, bdHolder)
BeanDefinitionParserDelegate.
decorateBeanDefinitionIfRequired(ele, originalDef, null)
decorateBeanDefinitionIfRequired(ele, originalDef, null)
decorateIfRequired(node, finalDefinition, containingBd)
getNamespaceURI(node)
this.readerContext.getNamespaceHandlerResolver().resolve(namespaceUri)
DefaultNamespaceHandlerResolver.
getHandlerMappings()
getHandlerMappings()
handlerMappings.get(namespaceUri)
BeanUtils.instantiateClass(handlerClass)
namespaceHandler.init()
handlerMappings.put(namespaceUri, namespaceHandler)
handler.decorate(node, originalDef, new ParserContext(this.readerContext, this, containingBd))
BeanDefinitionReaderUtils.registerBeanDefinition(bdHolder, getReaderContext().getRegistry())
getReaderContext().fireComponentRegistered(new BeanComponentDefinition(bdHolder))
doRegisterBeanDefinitions(ele)
delegate.parseCustomElement(ele)
BeanDefinitionParserDelegate.
parseCustomElement(ele, null)
parseCustomElement(ele, null)
getNamespaceURI(ele)
this.readerContext.getNamespaceHandlerResolver().resolve(namespaceUri)
handler.parse(ele, new ParserContext(this.readerContext, this, containingBd))
postProcessXml(root)
getBeanFactory()
3、prepareBeanFactory(beanFactory)
4、postProcessBeanFactory(beanFactory)
5、invokeBeanFactoryPostProcessors(beanFactory)
6、registerBeanPostProcessors(beanFactory)
7、initMessageSource()
8、initApplicationEventMulticaster()
9、onRefresh()
10、registerListeners()
11、finishBeanFactoryInitialization(beanFactory)
beanFactory.setTempClassLoader(null)
beanFactory.freezeConfiguration()
DefaultListableBeanFactory.
preInstantiateSingletons()
preInstantiateSingletons()
getMergedLocalBeanDefinition(beanName)
isFactoryBean(beanName)
getBean(FACTORY_BEAN_PREFIX + beanName)
AbstractBeanFactory.
getBean(beanName)
getBean(beanName)
transformedBeanName(name)
getSingleton(beanName)
getObjectForBeanInstance(sharedInstance, name, beanName, null
isPrototypeCurrentlyInCreation(beanName)
markBeanAsCreated(beanName)
mbd.getDependsOn()
getSingleton(String beanName, ObjectFactory<?> singletonFactory)
beforeSingletonCreation(beanName)
AbstractAutowireCapableBeanFactory.
getObject()
getObject()
resolveBeanClass(mbd, beanName)
mbdToUse.prepareMethodOverrides()
resolveBeforeInstantiation(beanName, mbdToUse)
doCreateBean(beanName, mbdToUse, args)
this.factoryBeanInstanceCache.remove(beanName)
createBeanInstance(beanName, mbd, args)
resolveBeanClass(mbd, beanName)
obtainFromSupplier(instanceSupplier, beanName)
instantiateUsingFactoryMethod(beanName, mbd, args)
autowireConstructor(beanName, mbd, null, null)
instantiateBean(beanName, mbd)
SimpleInstantiationStrategy
getInstantiationStrategy().instantiate(mbd, beanName, this)
getInstantiationStrategy().instantiate(mbd, beanName, this)
BeanUtils.instantiateClass(constructorToUse)
ctor.newInstance(args)
instantiateWithMethodInjection(bd, beanName, owner)
new BeanWrapperImpl(beanInstance)
initBeanWrapper(bw)
applyMergedBeanDefinitionPostProcessors(mbd, beanType, beanName)
addSingletonFactory(beanName, () -> getEarlyBeanReference(beanName, mbd, bean))
populateBean(beanName, mbd, instanceWrapper)
hasInstantiationAwareBeanPostProcessors()
autowireByName(beanName, mbd, bw, newPvs)
unsatisfiedNonSimpleProperties(mbd, bw)
registerDependentBean(propertyName, beanName);
autowireByType(beanName, mbd, bw, newPvs)
ibp.postProcessPropertyValues(pvs, filteredPds, bw.getWrappedInstance(), beanName)
applyPropertyValues(beanName, mbd, bw, pvs)
initializeBean(beanName, exposedObject, mbd)
registerDisposableBeanIfNecessary(beanName, bean, mbd)
afterSingletonCreation(beanName)
addSingleton(beanName, singletonObject
12、finishRefresh()
0 条评论
下一页