在此记录下,以便后面用到,再者,若是须要还能够继续更新此文。有些细节步骤被我省略了,建议读者本身去读源码。java
getProxy()方法,依据咱们对Proxy属性的设置,生成JdkDynamicAopProxy或者CglibAopProxy,咱们这里分析JdkDynamicAopProxy的场景。原图在Gtihub上。git
org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor org.springframework.aop.framework.adapter.ThrowsAdviceInterceptor
ProxyFactoryBean不一样于ProxyFactory,ProxyFactoryBean是个FactoryBean(若是是熟悉这个interface接口的同窗看到这个应该能想到点什么了吧,这里),它有个getObject()方法,Spring IOC在容器中由BeanDefinition生成bean对象时,会调用此方法,将getObject()的返回值做为bean对象。因此咱们从getObjects()开始分析起。github
这里咱们分析JdkDynamicAopProxy时候的场景。原图在Github上。spring
for (String name : this.interceptorNames) { if (logger.isTraceEnabled()) { logger.trace("Configuring advisor or advice '" + name + "'"); } if (name.endsWith(GLOBAL_SUFFIX)) { if (!(this.beanFactory instanceof ListableBeanFactory)) { throw new AopConfigException( "Can only use global advisors or interceptors with a ListableBeanFactory"); } addGlobalAdvisor((ListableBeanFactory) this.beanFactory, name.substring(0, name.length() - GLOBAL_SUFFIX.length())); } else { Object advice; if (this.singleton || this.beanFactory.isSingleton(name)) { //name是bean的Id,因此从beanFactory中直接getBean()便可。 advice = this.beanFactory.getBean(name); } else { // It's a prototype Advice or Advisor: replace with a prototype. // Avoid unnecessary creation of prototype bean just for advisor chain initialization. advice = new PrototypePlaceholderAdvisor(name); } //将获得的advice加入到拦截器链中 addAdvisorOnChainCreation(advice, name); } }
还有不少关键点没有写出来,我我的以为仍是本身去看源码比较好,有些地方很难用有限的语言清晰的描述出来。this