关于bean:Spring中bean的生命周期

public class Others implements BeanPostProcessor{
  public Others(){
    //第一步 调用无参数的构造方法创立bean实例
  }
  
  private String othername;
  public void setOtherName(String otherName){
    //第二步 调用set办法设置属性
  }
  
  public Object postProcessorBeforeInitialization(){
   //第3.1步 初始化之前执行的办法 前置处理器 **留神会对bean.xml中所有bean都增加该处理器**
  }
  
  public void initMethod(){
    //第三步 执行初始化办法
  }
  
  public Object postProcessorAfterInitialization(){
   //第3.2步 初始化之后执行的办法 后置处理器
  }
  
  public void destoryMethod(){
    //第五步 执行销毁办法
  }
}
public void test(){
  ApplicationContext context = new ClassPathXmlApplicationContext("bean.xml");
  Others others = context.getBean("others",Others.class);
  //第四步 获取创立Bean实例对象
  ((ClassPathXmlApplicationContext) context).close;
}
<bean id="others" class="com.zong.spring.Others" init-method="initMethod" destory-method="destoryMethod">

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理