Spring 5.x Source trip forty-one BeanFactoryPostProcessors extension points and BeanPostProcessor

Figure no less

Here Insert Picture Description

When the container calls the initialization invokeBeanFactoryPostProcessorsmethod BeanDefinitionRegistryPostProcessorand BeanFactoryPostProcessorcall the method, mainly internal ConfigurationClassPostProcessorconfiguration file to do the processing, the articles have talked about earlier, not to say, mainly to some of the places listed can be extended out, For example, we can extend the very beginning.

BeanDefinitionRegistryPostProcessor

Initially it will first call from the extended definition.
Here Insert Picture Description
For example, I want to register a beandefinition, it will at the very beginning register go:
Here Insert Picture Description

PriorityOrdered且BeanDefinitionRegistryPostProcessor

Then will come and get execution ordered by priority, including here ConfigurationClassPostProcessor, will go to parse the configuration file, the container classes we want to register all packaged into a beandefined register into it. :
Here Insert Picture Description

Ordered且BeanDefinitionRegistryPostProcessor

A logic, just go heavy, default will not have an internal processor, unless you define a can.
Here Insert Picture Description

The remaining BeanDefinitionRegistryPostProcessor

Finally, the rest:
Here Insert Picture Description

invokeBeanFactoryPostProcessors

Then we will go to the beginning of the implementation of customized BeanFactoryPostProcessorsand just registered BeanFactoryPostProcessortype of processor postProcessBeanFactorymethod:
Here Insert Picture Description

All BeanFactoryPostProcessor last treatment

Later will be BeanFactoryPostProcessorthe type of acquisition, and then to perform, because our custom or some inner class is BeanFactoryPostProcessorthe type of self may be defined from BeanDefinitionRegistryPostProcessoradded to the list, it did not handle the front, we had to deal with back once, also in order of priority of.

Here we are processing processor with plant-related, you can register and operate inside the beanfactory.

registerBeanPostProcessors注册BeanPostProcessor

Here Insert Picture Description
Here is all the BeanPostProcessorfound, instantiated and registered into the container.
Registration before:

Here Insert Picture Description
After registration:
Here Insert Picture Description
two are custom internal default is 6one.

ApplicationContextAwareProcessorBefore initialization is used to set the property:
Here Insert Picture Description
ImportAwareBeanPostProcessoris mainly CGLIBset to configure the agent class when the beanFactoryproperty, subject to ImportAware incoming metadata annotation:
Here Insert Picture Description
Here Insert Picture Description
CommonAnnotationBeanPostProcessorand AutowiredAnnotationBeanPostProcessoris the main job of the properties and methods of injection are:
Here Insert Picture Description
ApplicationListenerDetectoris the main job of listening registration is, if you beanare ApplicationListenerthe type of words:
Here Insert Picture Description
BeanPostProcessorCheckeris used to check the number of processors to create the right:
Here Insert Picture Description

Well, here today, we hope to help study and understand, do not spray the Great God see, understand only their own learning, limited capacity, please excuse.

Published 235 original articles · won praise 74 · views 30000 +

Guess you like

Origin blog.csdn.net/wangwei19871103/article/details/105180132