Org.springframework.beans.factory.DisposableBean interface has a following callback method for Bean in container when the container containing this bean is destroyed.

Java Code:
void destroy() throws Exception;
But for the aforementioned reason it should be avoided so following code is much better option

Java Code:
<bean id="sampleInitBean" class="sample.ExampleBean" destroy-method="cleanup"/>
public class SampleBean {
public void cleanup() {
// destruction code for bean (closing pooled connections etc)
}
}