The largest Interview Solution Library on the web


« Previous | 2 | | 4 | Next »

Spring Bean Life Cycle Tutorial

  • Spring bean factory is responsible for managing the life cycle of beans created through spring container.
  • The life cycle of beans consist of call back methods which can be categorized broadly in two groups:

  • Post initialization call back methods
  • Pre destruction call back methods
  • Spring framework provides following 4 ways for controlling life cycle events of bean:

  • InitializingBean and DisposableBean callback interfaces
  • Other Aware interfaces for specific behaviour
  • custom init() and destroy() methods in bean configuration file
  • @PostConstruct and @PreDestroy annotations
  • package com.jtc;
    import org.springframework.beans.factory.DisposableBean;
    import org.springframework.beans.factory.InitializingBean;
    public class DemoBeanTypeOne implements InitializingBean, DisposableBean
    {
    //Other bean attributes and methods
    @Override
    public void afterPropertiesSet() throws Exception
    {
    //Bean initialization code
    }
    @Override
    public void destroy() throws Exception
    {
    //Bean destruction code
    }
    }

    « Previous | 1 | 2 | 3 | Next »


    copyright © 2014 - all rights riserved by javatechnologycenter.com