Learning spring framework experience and summary. Attached: Spring source code comment address github.com/LXPWing/spr…

GetBean flowchart: www.processon.com/view/link/6…

Flow chart of the Bean lifecycle: www.processon.com/view/link/6…

DI flowchart: www.processon.com/view/link/6…

GetBean process

In the getBean process, Spring checks to see if the object is in the singleton pool, returns if it is, and continues the process of creating the object if it is not.

Start creating the Bean object

Enter the getSingleton method and call the lamda expression to enter the createBean(beanName, MBD, ARgs).

In createBean(beanName, MBD,args) BeanPostProcessors(the Bean’s post-processor) are first called to determine whether to return the proxy object.

If no proxy object is returned, the createBeanInstance(beanName, mbdToUser,args) method is called in doCreateBean(beanName, MBD,args).

Go into instantiateBean(beanName, MBD) and select object creation method via policy mode, JDK reflection /Cglib.

Go to getInstantiationStrategy().instantiate(MBD, beanName, this).

The last call BeanUtils. InstantiateClass (constructorToUse) complete object creation through reflection.

The object is created but not assigned.

  • DI process

After creating the object, go back to the main flow,Enter populateBean (beanName, MBD, instanceWrapper) for attribute assignment.

Enter the method first determines, whether to use rear InstantiationAwareBeanPostProcessor processor intervention

Inject property values in different ways (via reflection assignment)

Back to the main process into initializeBean (beanName exposedObject, MBD) initialization Bean object.

The BeanPostProcessor and InitializingBean post-processor intervene with the completed Bean object.

Returns the final Bean object.