Spring中bean的初始化和銷毀之前的方法XML和注解的兩種形式
XML形式
package cn.xy;
public class StudentServiceImpl
{
private StudentDao studentDao;
public void init()
{
System.out.println("正在執行初始化的init方法");
}
public void save(Student s)
{
studentDao.insert(s);
}
public void destory()
{
System.out.println("正在執行銷毀之前的destory方法");
}
public StudentDao getStudentDao()
{
return studentDao;
}
public void setStudentDao(StudentDao studentDao)
{
this.studentDao = studentDao;
}
}
<bean />
<bean init-method="init" destory-method="destory">
<property name="studentDao" ref="studentDao">
</bean>
注解形式
package cn.xy;
public class StudentServiceImpl
{
private StudentDao studentDao;
@PostConstruct
public void init()
{
System.out.println("正在執行初始化的init方法");
}
public void save(Student s)
{
studentDao.insert(s);
}
@PreDestory
public void destory()
{
System.out.println("正在執行銷毀之前的destory方法");
}
public StudentDao getStudentDao()
{
return studentDao;
}
@Resource
public void setStudentDao(StudentDao studentDao)
{
this.studentDao = studentDao;
}
}
最後更新:2017-04-02 15:28:22
上一篇:
java中Thread與Runnable的區別
下一篇:
Oracle中刪除用戶遇到的問題
≪統計學習精要(The Elements of Statistical Learning)≫課堂筆記(三)
《Netty實戰》Netty In Action中文版——文前內容
3.3.2 PCI設備對不可Cache的存儲器空間進行DMA讀寫
《Spring攻略(第2版)》——1.6 為集合元素指定數據類型
Nginx學習之location匹配規則
(流式、lambda、實時)數據處理方案大比拚 - 物聯網(IoT)最佳實踐
北大研討“天貓雙11”現象:新零售引擎,激發全球商業史上最大規模社會協同
談談Magento與淘寶API整合
關於weblogic配置pg和sqlserver數據源的注意事項
photoalbum 0.4.0 發布,靜態 HTML 相冊生成工具