Detailed explanation of the use of spring beanpostprocessor interface
Spring provides many postprocessors for developers to expand, such as beanpostprocessor, beanfactorypostprocessor, beanvalidation postprocessor and a series of postprocessors. Most of their use methods are similar. Understand one of them and master his use method, and the others can be bypassed by analogy.
Here, take beanpostprocessor as an example to show its usage.
The beanpostprocessor interface provides two methods for developers to customize: postprocessbeforeinitialization and postprocessafterinitialization.
Postprocessbeforeinitialization: this method is mainly used for spring to perform custom processing before calling the initialization method during bean initialization.
Postprocessafterinitialization: this method is mainly used for spring to perform custom processing after calling the initialization method during bean initialization.
Example code:
XML configuration information
Output results:
name:HelloKitty age:1 name:hello maomi age:3
You can see that the bean information processed by the post processor has changed. Finally, let's look at how the custom implementation is invoked in the source code.
In the initialization bean method: abstractautowirecapablebeanfactory java
The above is the calling process of spring to the custom method implementation. I hope it will help you in your study, and I also hope you can support programming tips.