Spring Bean Life Cycle


  • Initialization Callbacks
  • Destruction Callbacks

Initialization Callbacks

public class Example1 implements InitializingBean
{
    public void afterPropertiesSet()
    {
    }
}

<bean id="exampleBean" class="Example2" init-method="init"/>

public class Example2
{
    public void init()
    {
    }
}

Destruction Callbacks

public class Example1 implements DisposableBean
{
    public void destroy()
    {
    }
}

<bean id=”exampleBean” destroy-method=”destroy”/>

public class Example2
{
public void destroy()
{
}
}

AbstractApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");
context.registerShutdownHook();

Hello obj = (Hello) context.getBean("helloWorld");

System.out.println(obj.getMessage());
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s