Spring Framework Documentation (5.3.10)
Core | IoC Container, Events, Resources, i18n, Validation, Data Binding, Type Conversion, SpEL, AOP. |
1. The IoC Container
1.1. Introduction to the Spring IoC Container and Beans(Spring IoC容器和bean简介)
1.2. Container Overview (容器概览)
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:
- The InitializingBean and DisposableBean callback interfaces
- Custom
init()
anddestroy()
methods - The @PostConstruct and @PreDestroy annotations. You can combine these mechanisms to control a given bean.
从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 configured — for example, |
| 如果为一个bean配置了多个生命周期机制(lifecycle mechanism),并且每个机制都配置了不同的方法名称,那么每个配置的方法都将按照本说明后面列出的顺序运行。但是,如果配置了相同的方法名称 , 例如,初始化方法的init() ,对于这些生命周期机制中的多个,该方法只运行一次,如前一节所述。 |
Multiple lifecycle mechanisms configured for the same bean, with different initialization methods, are called as follows:
- Methods annotated with
@PostConstruct
afterPropertiesSet()
as defined by theInitializingBean
callback interface- A custom configured
init()
method
使用不同的初始化方法为同一bean配置的多个生命周期机制调用顺序如下:
- 用@PostConstruct注解的方法
- 由
InitializingBean
回调接口(callback interface)定义的afterPropertiesSet ()
- 自定义配置的init
()
方法
Destroy methods are called in the same order:
- Methods annotated with
@PreDestroy
destroy()
as defined by theDisposableBean
callback interface- A custom configured
destroy()
method
销毁方法的调用顺序相同:
- 用@PreDestroy注解的方法
DisposableBean
回调接口定义的destroy ()
- 自定义配置的
destroy ()
方法