1)创建对象(分配内存)
2)执行构造方法
3)执行属性注入(set操作)
4)执行bean初始化方法
1)执行业务操作
1)执行bean销毁方法
public class BookDaoImpl implements BookDao {
public void save(){
System.out.println("book dao save ...");
}
public void init(){
System.out.println("book init ...");
}
public void destory(){
System.out.println("book destory");
}
}
public class AppForLifeCycle {
public static void main(String[] args) {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
BookDao bookDao = (BookDao) ctx.getBean("bookDao");
bookDao.save();
ctx.registerShutdownHook();//先关容器
// ctx.close();暴力关闭
}
}
<bean
id="bookDao"
class="com.spring.dao.impl.BookDaoImpl"
init-method="init"
destroy-method="destory"/>