Spring Bean
LifeCycle:-
1. Spring
creates instance of bean using reflection API.
2. If any
properties are mentioned, apply them with setXXX().
3. If bean
class implements the BeanNameAware interface then call setBeanName() method.
4. If bean
class implements the ApplicationContextAware interface, than call
setApplicationContext() method.
5. If bean
class implements the BeanFactoryAware interface, then call setBeanFactory()
method.
6. If there are
any BeanPostProcessor associated with the BeanFactory that loads the bean, then
spring will call postProcessorBeforInitilization() method before the properties
for the bean are injected.
7. If the bean
class implements the InitializingBean interface, then call after
propertiesSet() once.
8. If there is
any custom init-method declare , method will get called.
9. If there are
any BeanPostProcessor associated with the BeanFactory, that loads the bean,
then spring will call postProcessorAfterInitialization() method.
10. Now bean is
ready to use.
11. If the bean
class implements the DisposableBean interface then call destroy() method.
12. If there is
any custom method destroy-method declared, call it
very usefull in full details thanks
ReplyDelete