在容器启动时初始化bean,再接着调用初始化方法init(),随着spring容器的关闭,最后会调用destroy方法来释放资源。
业务bean中的代码如下:
测试代码:
<bean id="personService" class="com.bill.impl.PersonServiceBean"
init-method="init" destroy-method="destroy"/>
业务bean中的代码如下:
public class PersonServiceBean implements PersonService {
public void init(){
System.out.println("init() function");
}
...
public void destroy(){
System.out.println("destroy resource");
}
}
测试代码:
AbstractApplicationContext act = new ClassPathXmlApplicationContext("beans.xml");
act.close();