在PersonServiceBean类中加入:
public void init()
{
System.out.println("spring初始化");
}
public void destroy()
{
System.out.println("spring销毁");
}
bean中的配置:
<bean id="personService" class="com.river.service.impl.PersonServiceBean" lazy-init="false" destroy-method="destroy" init-method="init" />
其中 destroy为对应的销毁方法名 init为初始化名
测试方法:
AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");
ctx.close();
测试结果:spring初始化 spring销毁
public void init()
{
System.out.println("spring初始化");
}
public void destroy()
{
System.out.println("spring销毁");
}
bean中的配置:
<bean id="personService" class="com.river.service.impl.PersonServiceBean" lazy-init="false" destroy-method="destroy" init-method="init" />
其中 destroy为对应的销毁方法名 init为初始化名
测试方法:
AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");
ctx.close();
测试结果:spring初始化 spring销毁