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

 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. 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 @PostConstruct and @PreDestroy annotations are generally considered best practice for receiving lifecycle callbacks in a modern Spring application. Using these annotations means that your beans are not coupled to Spring-specific interfaces. For details, see Using @PostConstruct and @PreDestroy.

If you do not want to use the JSR-250 annotations but you still want to remove coupling, consider init-method and destroy-method bean definition metadata.

JSR-250 @PostConstruct @PreDestroy 注解通常被认为是在现代Spring应用程序中接收生命周期回调的最佳实践。使用这些注解意味着您的bean没有耦合到特定于Spring的接口。有关详细信息,请参见Using @PostConstruct and @PreDestroy

如果不想使用JSR-250注解,但仍想删除耦合,请考虑init-methoddestroy-method bean定义元数据。

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),这是由容器自身的生命周期驱动的。

本节介绍生命周期回调接口。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

月满闲庭

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

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

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

打赏作者

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

抵扣说明:

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

余额充值