1.6.1.4. Combining Lifecycle Mechanisms(合并生命周期机制)

Spring Framework Documentation (5.3.10)

Core

IoC Container, Events, Resources, i18n, Validation, Data Binding, Type Conversion, SpEL, AOP.

   Core Technologies

1. The IoC Container

1.1. Introduction to the Spring IoC Container and Beans(Spring IoC容器和bean简介)

1.2. Container Overview (容器概览)

1.3. Bean Overview (Bean概览)

1.4. Dependencies(依赖)

1.5. Bean Scopes(Bean作用域)

1.6. Customizing the Nature of a Bean (自定义bean的性质)

1.6.1. Lifecycle Callbacks 生命周期回调

1.6.1.1. Initialization Callbacks 初始化回调

1.6.1.2. Destruction Callbacks 销毁回调

1.6.1.3. Default Initialization and Destroy Methods默认初始化和销毁方法

1.6.1.4. Combining Lifecycle Mechanisms (合并生命周期机制)

1.6.1.5. Startup and Shutdown Callbacks 启动和停止回调

1.6.1.6. Shutting Down the Spring IoC Container Gracefully in Non-Web Applications 在非web应用程序优雅地关闭Spr

1.6.2. ApplicationContextAware and BeanNameAware

1.6.3. Other Aware Interfaces 其它Aware接口

1.7. Bean Definition Inheritance(Bean定义继承)

1.8. Container Extension Points (容器扩展点)


下载此文档精编完整版

No.内容下载地址文档内容目录
1中英双语精编版 第一部分PDF下载内容目录
2中英双语精编版 第二部分PDF下载内容目录
3中文精编版 第一部分PDF下载内容目录
4中文精编版 第二部分PDF下载内容目录

更多章节内容,请点击查看:  Core Technologies


1.6.1.4. Combining Lifecycle Mechanisms 合并生命周期机制

As of Spring 2.5, you have three options for controlling bean lifecycle behavior:

Spring 2.5开始,您有三个控制bean生命周期行为(bean lifecycle behavior)的选项:

  • InitializingBean DisposableBean 回调接口
  • 自定义init() destroy() 方法
  • @PostConstruct@PreDestroy注解。您可以组合这些机制来控制给定的bean

If multiple lifecycle mechanisms are configured for a bean and each mechanism is configured with a different method name, then each configured method is run in the order listed after this note. However, if the same method name is configuredfor example, init()  for an initialization methodfor more than one of these lifecycle mechanisms, that method is run once, as explained in the preceding section.

如果为一个bean配置了多个生命周期机制(lifecycle mechanism),并且每个机制都配置了不同的方法名称,那么每个配置的方法都将按照本说明后面列出的顺序运行。但是,如果配置了相同的方法名称例如,初始化方法的init() ,对于这些生命周期机制中的多个,该方法只运行一次,如前一节所述。

Multiple lifecycle mechanisms configured for the same bean, with different initialization methods, are called as follows:

  1. Methods annotated with @PostConstruct
  2. afterPropertiesSet()  as defined by the InitializingBean callback interface
  3. A custom configured init()  method

使用不同的初始化方法为同一bean配置的多个生命周期机制调用顺序如下:

  1. 用@PostConstruct注解的方法
  2. InitializingBean 回调接口(callback interface)定义的afterPropertiesSet ()
  3. 自定义配置的init() 方法

Destroy methods are called in the same order:

  1. Methods annotated with @PreDestroy
  2. destroy()  as defined by the DisposableBean callback interface
  3. A custom configured destroy()  method

销毁方法的调用顺序相同:

  1. 用@PreDestroy注解的方法
  2. DisposableBean 回调接口定义的destroy ()
  3. 自定义配置的destroy () 方法

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

月满闲庭

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值