生命周期
- 定义
- 初始化
- 使用
- 销毁
方法
初始化、销毁
- 实现接口InitializingBean, DisposableBean
public class BeanLifeCycle implements InitializingBean, DisposableBean{
@Override
public void destroy() throws Exception {
System.out.println("Bean destroy.");
}
@Override
public void afterPropertiesSet() throws Exception {
System.out.println("Bean afterPropertiesSet.");
}
}
- xml配置 init-method="start" destroy-method="stop"
<bean id="beanLifeCycle" class="com.imooc.lifecycle.BeanLifeCycle" init-method="start" destroy-method="stop"></bean>
default-init-method="defautInit" default-destroy-method="defaultDestroy"
public void defautInit() {
System.out.println("Bean defautInit.");
}
public void defaultDestroy() {
System.out.println("Bean defaultDestroy.");
}
网友评论