<bean id="exampleInitBean" class="examples.ExampleBean" init-method="init"/>
public class ExampleBean { public void init() { // do some initialization work } }
<beans default-init-method="init">...</beans>
<bean id="exampleInitBean" class="examples.ExampleBean" destroy-method="cleanup"/>
public class ExampleBean { public void cleanup() { // do some destruction work (like releasing pooled connections) } }
<beans default-destroy-method="init">...</beans>
补充:Spring容器的应用上下文的生命周期管理方法
org.springframework.context.Lifecycle接口
start()
stop()isRunning()