Explain Spring Bean LifeCycle?

Steps for Bean LifeCycle-----------
  • Container will look the bean definition inside configuration file .(Xml file)
  • Container read the bean definitions .than create the Bean instances  by calling the appropriate constructor.
  • Than Container  inject the Bean dependencies by using Setter injection or Construcor injection.
  •  If the bean implements the BeanNameAware interface, the factory calls setBeanName() passing the bean’s ID.
  •  If the bean implements the BeanFactoryAware interface, the factory calls setBeanFactory(), passing an instance of itself.
  •  If there are any BeanPostProcessors associated with the bean, their post- ProcessBeforeInitialization () methods will be called before the properties for the Bean are set.
  • If there are any BeanPostProcessors associated with the bean, their  post- ProcessAfterInitialization () methods will be called After the properties for the Bean are set
  •  If an init-method is specified for the bean, it will be called.
  •  If the Bean class implements the DisposableBean interface, then the method destroy() will be called when the Application no longer needs the bean reference.
  •  If the Bean definition in the Configuration file contains a 'destroy-method' attribute, then the corresponding method definition in the Bean class will be called.


0 comments :

Post a Comment