






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
this notes describes shortly about the spring bean life cycle management technique
Typology: Study notes
1 / 12
This page cannot be seen from the preview
Don't miss anything!







7.2 InitializingBean and DisposbleBean callback interfaces
@Override public void destroy() throws Exception { System.out.println("destroy method of person bean is called !! "); } @Override
public void afterPropertiesSet() throws Exception { called !! ");System.out.println("afterPropertiesSet method^ of^ person^ bean is } public String getName() { return name; } public void setName(String name) { this.name = name; } }
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/ beans http://www.springframework.org/schema/beans/spring- beans-3.0.xsd">
import org.springframework.context.ApplicationContext; import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class TestPersonBean { public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml"); ("personBean");PersonBean bean =^ (PersonBean)context.getBean System.out.println(bean.getName()); ((AbstractApplicationContext) context).registerShutdownHook (); }
7.4.1 Example
public class CustomLifeCycleMethodBean { private String name;
public CustomLifeCycleMethodBean() { System.out.println("Constructor of bean is called !! "); }
public void customDestroy() throws Exception {
called !! ");^ System.out.println("custom^ destroy method^ of^ bean^ is
public void customInit() throws Exception { System.out.println("custom Init method of bean is called !! "); }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
7.4.2 – Example
public class CustomGlobalLifeCycleMehodBean { public CustomGlobalLifeCycleMehodBean() { System.out.println("Constructor of bean is called !! "); } public void globalCustomDestroy() throws Exception { called !! ");System.out.println("global^ custom^ destroy^ method^ of^ bean^ is } public void globalCustomInit() throws Exception { System.out.println("global custom Init method of bean is called !! ");
import org.springframework.context.ApplicationContext; import org.springframework.context.support.AbstractApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;
public class TestCustomGlobalMethodLifeCycleBean {