一、bean生命周期
1、初始化容器
1)創(chuàng)建對象(分配內存)
2)執(zhí)行構造方法
3)執(zhí)行屬性注入(set操作)
4)執(zhí)行bean初始化方法
2、使用bean
1)執(zhí)行業(yè)務操作文章來源:http://www.zghlxwxcb.cn/news/detail-784320.html
3、關閉/銷毀容器
1)執(zhí)行bean銷毀方法文章來源地址http://www.zghlxwxcb.cn/news/detail-784320.html
二、使用
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"/>
到了這里,關于【Spring】—— bean生命周期的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網!