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. Customizing the Nature of a Bean 自定义bean的性质
The Spring Framework provides a number of interfaces you can use to customize the nature of a bean. This section groups them as follows:
Spring框架提供了许多接口,您可以使用这些接口来定制bean的性质。本节将其分组如下:
1.6.1. Lifecycle Callbacks 生命周期回调
To interact with the container’s management of the bean lifecycle, you can implement the Spring InitializingBean
and DisposableBean
interfaces. The container calls afterPropertiesSet()
for the former and destroy()
for the latter to let the bean perform certain actions upon initialization and destruction of your beans.
为了与容器对bean生命周期的管理进行交互,可以实现Spring InitializingBean
和DisposableBean
接口。容器为前者调用afterPropertiesSet()
,为后者调用destroy()
,以便bean在初始化bean和销毁bean时执行某些操作。
| The JSR-250 If you do not want to use the JSR-250 annotations but you still want to remove coupling, consider |
| JSR-250 @ 如果不想使用JSR-250注解,但仍想删除耦合,请考虑 |
Internally, the Spring Framework uses BeanPostProcessor
implementations to process any callback interfaces it can find and call the appropriate methods. If you need custom features or other lifecycle behavior Spring does not by default offer, you can implement a BeanPostProcessor
yourself. For more information, see Container Extension Points.
在内部,Spring框架使用BeanPostProcessor
实现来处理它可以找到的任何回调接口,并调用适当的方法。如果您需要定制功能或需要Spring默认不提供的其他生命周期行为,您可以自己实现BeanPostProcessor
。有关详细信息,请参见容器扩展点(Container Extension Points)。
In addition to the initialization and destruction callbacks, Spring-managed objects may also implement the Lifecycle
interface so that those objects can participate in the startup and shutdown process, as driven by the container’s own lifecycle.
The lifecycle callback interfaces are described in this section.
除了初始化和销毁回调(initialization and destruction callback)之外,Spring托管对象还可以实现生命周期接口,以便这些对象可以参与启动和关闭过程(startup and shutdown process),这是由容器自身的生命周期驱动的。
本节介绍生命周期回调接口。