one , The creation process of proxy object :

AbstractAutowireCapableBeanFactory#initializeBean

protectedObjectinitializeBean(StringbeanName,Objectbean,@NullableRootBeanDefinitionmbd){
if(System.getSecurityManager()!=null){
AccessController.doPrivileged((PrivilegedAction<Object>)()->{
invokeAwareMethods(beanName,bean); return null; },getAccessControlContext()); }
else{ invokeAwareMethods(beanName,bean); } ObjectwrappedBean=bean;
if(mbd==null||!mbd.isSynthetic()){ //
Hold on to ⾏ be-all BeanPostProcessor#postProcessBeforeInitialization Before initialization Processor for ⽅ method
wrappedBean=applyBeanPostProcessorsBeforeInitialization(wrappedBean,beanName);
} try{ // this ⾥ I started to hold on ⾏afterPropertiesSet( Realized InitializingBean meet ⼝)⽅ Fa he initMethod
invokeInitMethods(beanName,wrappedBean,mbd); } catch(Throwableex){
thrownewBeanCreationException((mbd!=null?
mbd.getResourceDescription():null),beanName,"Invocationofinitmethodfailed",ex);
} if(mbd==null||!mbd.isSynthetic()){ // whole Bean Initialization complete , Hold on to ⾏ Post Processors ⽅ method
wrappedBean=applyBeanPostProcessorsAfterInitialization(wrappedBean,beanName); }
return wrappedBean; }
You can see that there are methods executed before initialization , Method executed on initialization , Method executed after initialization , We start with the method executed after initialization .

 

two ,applyBeanPostProcessorsAfterInitialization

applyBeanPostProcessorsAfterInitialization() The flow of the method is as follows :

AbstractAutowireCapableBeanFactory#applyBeanPostProcessorsAfterInitialization
->AbstractAutoProxyCreator#postProcessAfterInitialization
applyBeanPostProcessorsAfterInitialization Check whether the class has been exposed
( It may have been created ,⽐ as A rely on B Time , establish A time , We'll create it first B. When you really need to create B Time , There's no need to act as an agent ⼀ Objects that have been proxied ), Avoid duplicate creation .
->AbstractAutoProxyCreator#wrapIfNecessary
Get all the candidates Advisor, yes Advisors and bean Of ⽅ Double layer ergodic matching based on method , Finally get ⼀ individual List<Advisor>, Namely specificInterceptors
->AbstractAutoProxyCreator#createProxy
(1) To create a proxy ⼯ Give it to ProxyFactory

(2) To assign and communicate ⽤ Intercept object merging , And all fit together Advisor

(3) upper ⾯ When you're ready, start creating the agent
->proxyFactory.getProxy()
⽤ProxyFactory establish AopProxy, then ⽤AopProxy establish Proxy,
So that's it ⾥ It's important to see what you get AopProxy What is the target , Then go in and see how to create a dynamic proxy , Two methods are provided :jdk proxy, cglib

 

summary : Brief process

 

Technology