1 The container finds the bean’s definition and instantiates the bean.
2 Using dependency injection, Spring populates all of the properties as
specified in the bean definition.
3 If the bean implements the BeanNameAware interface, the factory calls
setBeanName() passing the bean’s ID.
4 If the bean implements the BeanFactoryAware interface, the factory calls
setBeanFactory(), passing an instance of itself.
5 If there are any BeanPostProcessors associated with the bean, their post-
ProcessBeforeInitialization() methods will be called.
6 If an init-method is specified for the bean, it will be called.
7 Finally, if there are any BeanPostProcessors associated with the bean,
their postProcessAfterInitialization() methods will be called.
At this point, the bean is ready to be used by an application and will remain in the
bean factory until it is no longer needed. It is removed from the bean factory in
two ways.
1 If the bean implements the DisposableBean interface, the destroy()
method is called.
2 If a custom destroy-method is specified, it will be called.
The life cycle of a bean within a Spring application context differs only slightly
from that of a bean within a bean factory
The only difference here is that if the bean implements the ApplicationContext-
Aware interface, the setApplicationContext() method is called.
No comments:
Post a Comment