Spring中bean的初始化和销毁之前的方法XML和注解的两种形式
来源:互联网 发布:3d动漫设计软件 编辑:程序博客网 时间:2024/05/16 11:01
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 id="studentDao" class="cn.xy.StudentDao" />
<bean id="studentService" class="cn.xy.StudentServiceImpl" 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;
}
}
- Spring中bean的初始化和销毁之前的方法XML和注解的两种形式
- Spring下的Bean初始化和销毁两种方式
- Spring下的Bean初始化和销毁两种方式
- 初始化和销毁bean之前的添加操作的方法
- 通过Spring @PostConstruct 和 @PreDestroy 方法 实现初始化和销毁bean之前进行的操作
- 通过Spring @PostConstruct 和 @PreDestroy 方法 实现初始化和销毁bean之前进行的操作
- Spring @PostConstruct 和 @PreDestroy 方法 实现初始化和销毁bean之前进行的操作
- 通过Spring @PostConstruct 和 @PreDestroy 方法 实现初始化和销毁bean之前进行的操作
- 通过Spring @PostConstruct 和 @PreDestroy 方法 实现初始化和销毁bean之前进行的操作
- 通过Spring @PostConstruct 和 @PreDestroy 方法 实现初始化和销毁bean之前进行的操作
- 通过Spring @PostConstruct 和 @PreDestroy 方法 实现初始化和销毁bean之前进行的操作
- 通过Spring @PostConstruct 和 @PreDestroy 方法 实现初始化和销毁bean之前进行的操作
- 通过Spring @PostConstruct 和 @PreDestroy 方法 实现初始化和销毁bean之前进行的操作
- 通过Spring @PostConstruct 和 @PreDestroy 方法 实现初始化和销毁bean之前进行的操作
- 通过Spring @PostConstruct 和 @PreDestroy 方法 实现初始化和销毁bean之前进行的操作
- 通过Spring @PostConstruct 和 @PreDestroy 方法 实现初始化和销毁bean之前进行的操作
- 通过Spring @PostConstruct 和 @PreDestroy 方法 实现初始化和销毁bean之前进行的操作
- 通过Spring @PostConstruct 和 @PreDestroy 方法 实现初始化和销毁bean之前进行的操作
- 安装hadoop和gluster
- hdu 1897 SnowWolf's Wine Shop multiset 运用 STL
- QiuQiu大事件
- 退出应用程序杀死进程
- C++默认构造函数——深入理解
- Spring中bean的初始化和销毁之前的方法XML和注解的两种形式
- 对MySQL load data infile的一点想法
- 使用system.out.println输出类名问题
- [init.rc] android init.rc 总结
- Oracle SOA Suite 学习笔记(一)
- C语言/C++基础知识
- .Net企业级应用架构设计之当代的架构师和架构
- Linux内核IP Queue机制的分析(一)——用户态接收数据包
- 行为模式之-观察者模式