The life cycle of the Bean
- Spring starts, finds and loads beans that need to be managed by Spring, instantiates, and creates a bean object.
- Populate the properties and assign values to the Bean’s properties.
- Initialize (if the ×××Aware interface is implemented, fetch resources from the SPring container through different types of Aware interfaces; If it implements the BeanPostProcessor interface callback postProcessBeforeInitialzation and postProcessAfterInitialization methods of the interface; The init-method method will execute the init-method configured method, which will call their afterPropertiesSet() method. Similarly, if the bean declares an initialization method with init-method, that method will be called.
- The Bean is ready to be used by the application. They will reside in the application context until the application context is destroyed.
- Destruction stage (after the container closes, if the Bean implements the DisposableBean interface, the destroy method of the interface will be called back)
Initialize the process method
Destroy method
When the BeanFactory is closed, the Bean lifecycle calls the following methods:
- DestructionAwareBeanPostProcessor. PostProcessBeforeDestruction () : before destruction the BeanPostProcessor was applied to the given bean instance. The ability to call custom callbacks, such as the destruction and custom destruction methods of DisposableBean, which only apply to singleton beans (including internal beans) in the factory
- Implements a custom deStory () method