Define init and destroy method for the spring bean (1. annotated with PostConstruct and PreDestroy 2. define in the web.xml 3. implements InitializingBean, DisposableBean)
<bean id="foo" class="com.wiley.beginningspring.ch2.Foo" init-method="init" destroy-method="destroy"/>
public class Baz implements InitializingBean, DisposableBean {
@Override
public void afterPropertiesSet() throws Exception {
System.out.println("init method invoked");
}
@Override
public void destroy() throws Exception {
System.out.println("destroy method invoked");
}
}
// Need to have <context:annotation-config/> in the web.xml
public class Bar {
@PostConstruct
public void init() throws Exception {
System.out.println("init method is called");
}
@PreDestroy
public void destroy() throws RuntimeException {
System.out.println("destroy method is called");
}
}