spring-IOC容器bean生命周期 2017-04-14 17:20 36人阅读 评论(0) 收藏

  1. Spring IOC 容器可以管理 Bean 的生命周期, Spring 允许在 Bean 生命周期的特定点执行定制的任务.
  2. Spring IOC 容器对 Bean 的生命周期进行管理的过程:
    通过构造器或工厂方法创建 Bean 实例
    为 Bean 的属性设置值和对其他 Bean 的引用
    Bean 可以使用了
    当容器关闭时, 调用 Bean 的销毁方法
  3. 在 Bean 的声明里设置 init-method 和 destroy-method 属性, 为 Bean 指定初始化和销毁方法.
<bean id="car" class="com.xzcl.spring.beans.cysle.Car" 
    init-method="init" destroy-method="destroy" >
        <property name="brand" value="aodi"></property>
        <property name="price" value="3000"></property>
    </bean>
posted @ 2017-04-14 17:20  xzcl  阅读(118)  评论(0编辑  收藏  举报