`
weini174
  • 浏览: 4073 次
  • 性别: Icon_minigender_1
  • 来自: 河北
社区版块
存档分类
最新评论

Spring - Initializing and destroying beans

 
阅读更多

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()

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics