Sunday 20 March 2011

Spring : DisposableBean Interface and InitializingBean

The InitializingBean and DisposableBean are two marker interfaces which call the  afterPropertiesSet() for the begining and destroy() for the last action of initialization and    destruction to be performed.

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;

public class StudentService implements InitializingBean, DisposableBean {
String message;

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}

public void afterPropertiesSet() throws Exception {
System.out.println(" After properties has been set : " + message);
}

public void destroy() throws Exception {
System.out.println("Cleaned everything!!");
}

}


In context.xml bean is created in usual style.

No comments:

Post a Comment