1. 使用init-method和destroy-method属性:
<bean id="kenny" class="com.springinaction.springidol.Instrumentalist"
init-method="tuneInstrument"
destroy-method="cleanInstrument">
<property name="song" value="Jingle Bells" />
<property name="instrument" ref="saxophone" />
</bean>
2. 使用default-init-method and default-destroy-method属性:
<?xml version="1.0" encoding="UTF-8"?>
<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-2.0.xsd"
default-init-method="tuneInstrument"
default-destroy-method="cleanInstrument"> ...
</beans>
3. 实现InitializingBean and DisposableBean():
InitializingBean.afterPropertiesSet()
DisposableBean.destroy()