The life cycle of Spring Bean?
Instantiation -> Attribute Assignment -> Initialization -> Destruction
- createBeanInstance() -> instantiate
- populateBean() -> attribute assignment, corresponding to the injection of the constructor and setter method
- initializeBean() -> initialization, users can customize the extension
- Destroyed when the container is closed.
Spring's core interface (commonly used)
BeanPostProcessor interface
Function: It is to add our own logic before and after actively calling the initialization method after the Bean object is instantiated and dependency injected .
method |
illustrate |
---|---|
postProcessBeforeInitialization |
Instantiation and dependency injection are complete, and some custom initialization tasks are completed before calling the displayed initialization |
postProcessAfterInitialization |
Executed when instantiation, dependency injection, and initialization are complete |
Usage learning: