美文网首页
org.springframework.beans.factor

org.springframework.beans.factor

作者: moralok | 来源:发表于2020-04-15 18:24 被阅读0次
package org.springframework.beans.factory;

/**
 * Interface to be implemented by beans that need to react once all their properties
 * have been set by a {@link BeanFactory}: e.g. to perform custom initialization,
 * or merely to check that all mandatory properties have been set.
 *
 * <p>An alternative to implementing {@code InitializingBean} is specifying a custom
 * init method, for example in an XML bean definition. For a list of all bean
 * lifecycle methods, see the {@link BeanFactory BeanFactory javadocs}.
 *
 * @author Rod Johnson
 * @author Juergen Hoeller
 * @see DisposableBean
 * @see org.springframework.beans.factory.config.BeanDefinition#getPropertyValues()
 * @see org.springframework.beans.factory.support.AbstractBeanDefinition#getInitMethodName()
 */
public interface InitializingBean {

    /**
     * Invoked by the containing {@code BeanFactory} after it has set all bean properties
     * and satisfied {@link BeanFactoryAware}, {@code ApplicationContextAware} etc.
     * <p>This method allows the bean instance to perform validation of its overall
     * configuration and final initialization when all bean properties have been set.
     * @throws Exception in the event of misconfiguration (such as failure to set an
     * essential property) or if initialization fails for any other reason
     */
    void afterPropertiesSet() throws Exception;

}

简介

org.springframework.beans.factory.Aware 的一个子接口。

文档

BeanFactory 设置完所有属性后需要立即响应的bean所实现的接口:执行自定义初始化,或仅检查是否已设置所有必填属性。

实现 InitializingBean 的另一种方法是指定自定义 init 方法,例如在 XML bean 定义中。

有关所有 bean生命周期 方法的列表,请参见 BeanFactory javadocs

afterPropertiesSet

由包含的 BeanFactory 设置了所有 bean属性 并满足 BeanFactoryAwareApplicationContextAware 等之后调用。
设置所有 bean属性 后,此方法允许 bean实例 执行其整体配置的验证和最终初始化。
@throws 在配置错误(例如无法设置基本属性)或初始化由于任何其他原因而失败的情况下发生的异常。

相关文章

网友评论

      本文标题:org.springframework.beans.factor

      本文链接:https://www.haomeiwen.com/subject/zbqhvhtx.html