XML AOP 加载流程
- ClassPathXmlApplicationContext#refresh
- AbstractApplicationContext#obtainFreshBeanFactory
- AbstractRefreshableApplicationContext#refreshBeanFactory
- 创建DefaultListableBeanFactory
- AbstractApplicationContext#loadBeanDefinitions(beanFactory)
- 创建XmlBeanDefinitionReader(beanFactory)
- AbstractApplicationContext#loadBeanDefinitions(beanDefinitionReader)
- AbstractBeanDefinitionReader#loadBeanDefinitions(locations)
- XmlBeanDefinitionReader#loadBeanDefinitions(encodedResource)
- XmlBeanDefinitionReader#doLoadBeanDefinitions(inputSource, resource)
- XmlBeanDefinitionReader#registerBeanDefinitions(doc, resource)
- 创建DefaultBeanDefinitionDocumentReader对象
- DefaultBeanDefinitionDocumentReader#registerBeanDefinitions(doc, readerContext)
- DefaultBeanDefinitionDocumentReader#doRegisterBeanDefinitions(element)
- DefaultBeanDefinitionDocumentReader#parseBeanDefinitions(element, delegate)
- 解析默认标签:DefaultBeanDefinitionDocumentReader#parseDefaultElement
- 解析非默认标签:BeanDefinitionParserDelegate#parseCustomElement(ele)
解析非默认标签
- 通过element获取namespaceUri
- 从readerContext中获取NamespaceHandler: DefaultNamespaceHandlerResolver
- DefaultNamespaceHandlerResolver#resolve(namespaceUri)
- 从META-INF/spring.handlers中加载所有的handlerMapping并根据namespaceUri获取匹配的值
- 实例化AopNamespaceHandler并调用init进行初始化,并返回实例对象
- NamespaceHandlerSupport#parse(element, parserContext) 解析标签beanDefinition信息
- 根据标签获取AopNamespaceHandler中注册的BeanDefinitionParser
- ConfigBeanDefinitionParser#parse(element, parserContext)解析pointcut, advisor, aspect信息