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 相册生成工具