天天看点

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 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>

注解形式

 @postconstruct

 @predestory

 @resource