What is Spring Bean life cycle?

What is Spring Bean life cycle?

 Standard bean lifecycle interfaces & there standard order of execution are given below..
 1- IoC container will look for the configuration metadata of given Bean.
 2- Once find, container will create the instance of Bean(Using reflection API).
 3- After instance creation dependency will be injected(DI).
 4- setBeanName method of BeanNameAware class. It sets the name of the bean in the bean factory that  created this bean.
 5- setBeanClassLoader method of BeanClassLoaderAware class. Callback that supplies the bean to a  bean instance.
 6- setBeanFactory method of BeanFactoryAware class. Callback that supplies the owning factory to a  bean instance.
 7- setResourceLoader method of ResourceLoaderAware class. It set the ResourceLoader that this  object runs in.
 8- setApplicationEventPublisher method of ApplicationEventPublisherAware class. Set the  ApplicationEventPublisher that this object runs in.
 9- setMessageSource method of MessageSourceAware class. Set the MessageSource that this object  runs in.
 10- setApplicationContext method of ApplicationContextAware class. Set the ApplicationContext that  this object runs in.
 11- setServletContext method of ServletContextAware. Set the ServletContext that this object runs in.
 12- postProcessBeforeInitialization method of BeanPostProcessor. Apply this BeanPostProcessor to    the given new bean instance before any bean initialization callbacks.
 13- afterPropertiesSet method of InitializingBean. Invoked by a BeanFactory after it has set all bean  properties supplied.
 14- Custom init method will be invoked.
 15- postProcessAfterInitialization methods of BeanPostProcessors. Apply this BeanPostProcessor to  the given new bean instance after any bean initialization callbacks
  When Bean Factory is getting shut down following lifecycle methods will be executed.
 1- DisposableBean’s destroy method. Invoked by a BeanFactory on destruction of a singleton.
 2- Custome destroy method will be executed if there is any defined via destroy-method attributes.

Read More →
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!