美文网首页
寻找AOP的入口

寻找AOP的入口

作者: eqgao | 来源:发表于2019-07-28 14:21 被阅读0次

    参照Spring IOC 源码,BeanDefinition 加载以及注册的流程

    解析标签阶段<aop:config>标签为例子(注册BeanPostProcessor)

    org.springframework.context.support.AbstractApplicationContext#refresh
    org.springframework.context.support.AbstractApplicationContext#obtainFreshBeanFactory
    org.springframework.context.support.AbstractRefreshableApplicationContext#refreshBeanFactory
    org.springframework.context.support.AbstractXmlApplicationContext#loadBeanDefinitions(org.springframework.beans.factory.support.DefaultListableBeanFactory)
    org.springframework.context.support.AbstractXmlApplicationContext#loadBeanDefinitions(org.springframework.beans.factory.xml.XmlBeanDefinitionReader)
    org.springframework.beans.factory.support.AbstractBeanDefinitionReader#loadBeanDefinitions(org.springframework.core.io.Resource...)
    org.springframework.beans.factory.xml.XmlBeanDefinitionReader#loadBeanDefinitions(org.springframework.core.io.Resource)
    org.springframework.beans.factory.xml.XmlBeanDefinitionReader#loadBeanDefinitions(org.springframework.core.io.support.EncodedResource)
    org.springframework.beans.factory.xml.XmlBeanDefinitionReader#doLoadBeanDefinitions
    org.springframework.beans.factory.xml.XmlBeanDefinitionReader#registerBeanDefinitions
    org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader#registerBeanDefinitions
    org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader#doRegisterBeanDefinitions
    org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader#parseBeanDefinitions
    org.springframework.beans.factory.xml.BeanDefinitionParserDelegate#parseCustomElement(org.w3c.dom.Element)
    org.springframework.beans.factory.xml.BeanDefinitionParserDelegate#parseCustomElement(org.w3c.dom.Element, org.springframework.beans.factory.config.BeanDefinition)
    org.springframework.beans.factory.xml.NamespaceHandlerSupport#parse
    org.springframework.aop.config.ConfigBeanDefinitionParser#parse
    org.springframework.aop.config.ConfigBeanDefinitionParser#configureAutoProxyCreator
    org.springframework.aop.config.AopNamespaceUtils#registerAspectJAutoProxyCreatorIfNecessary
    org.springframework.aop.config.AopConfigUtils#registerAspectJAutoProxyCreatorIfNecessary(org.springframework.beans.factory.support.BeanDefinitionRegistry, java.lang.Object)
    org.springframework.beans.factory.support.DefaultListableBeanFactory#registerBeanDefinition

    实例化Bean阶段 (执行BeanPostProcessors接口的postProcessAfterInitialization方法)

    org.springframework.context.support.AbstractApplicationContext#refresh
    org.springframework.context.support.AbstractApplicationContext#finishBeanFactoryInitialization
    org.springframework.beans.factory.support.AbstractBeanFactory#getBean(java.lang.String, java.lang.Class<T>)
    org.springframework.beans.factory.support.AbstractBeanFactory#doGetBean
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory#createBean(java.lang.String, org.springframework.beans.factory.support.RootBeanDefinition, java.lang.Object[])
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory#doCreateBean
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory#initializeBean(java.lang.String, java.lang.Object, org.springframework.beans.factory.support.RootBeanDefinition)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory#applyBeanPostProcessorsAfterInitialization

    总结

    解析标签阶段

    1564293606756.png

    如图在解析标签阶段,注册了一个AspectJAwareAdvisorAutoProxyCreator, AspectJAwareAdvisorAutoProxyCreator是一个实现了BeanPostProcessor的类。

    它在IOC执行总体的位置如下。


    1564293849060.png

    实例化Bean阶段

    在实例化Bean的阶段,获取BeanPostProcessor,并且执行。所以执行了AbstractAutowireCapableBeanFactory#applyBeanPostProcessorsAfterInitialization。所以Spring AOP的入口是在AspectJAwareAdvisorAutoProxyCreator.postProcessAfterInitialization()方法(父类)

    它在IOC执行总体的位置如下。

    1564293931858.png

    相关文章

      网友评论

          本文标题:寻找AOP的入口

          本文链接:https://www.haomeiwen.com/subject/pvaurctx.html