org.springframework.beans.factory.DisposableBean

package org.springframework.beans.factory;

/**
 * Interface to be implemented by beans that want to release resources on destruction.
 * A {@link BeanFactory} will invoke the destroy method on individual destruction of a
 * scoped bean. An {@link org.springframework.context.ApplicationContext} is supposed
 * to dispose all of its singletons on shutdown, driven by the application lifecycle.
 *
 * <p>A Spring-managed bean may also implement Java's {@link AutoCloseable} interface
 * for the same purpose. An alternative to implementing an interface is specifying a
 * custom destroy method, for example in an XML bean definition. For a list of all
 * bean lifecycle methods, see the {@link BeanFactory BeanFactory javadocs}.
 *
 * @author Juergen Hoeller
 * @since 12.08.2003
 * @see InitializingBean
 * @see org.springframework.beans.factory.support.RootBeanDefinition#getDestroyMethodName()
 * @see org.springframework.beans.factory.config.ConfigurableBeanFactory#destroySingletons()
 * @see org.springframework.context.ConfigurableApplicationContext#close()
 */
public interface DisposableBean {

    /**
     * Invoked by the containing {@code BeanFactory} on destruction of a bean.
     * @throws Exception in case of shutdown errors. Exceptions will get logged
     * but not rethrown to allow other beans to release their resources as well.
     */
    void destroy() throws Exception;

}

簡介

org.springframework.beans.factory.Aware 的一個(gè)子接口。

文檔

要在銷毀時(shí)釋放資源的 bean 所實(shí)現(xiàn)的接口。BeanFactory 將在 有作用域的bean 單獨(dú)銷毀時(shí)調(diào)用 destroy 方法。 一個(gè) org.springframework.context.ApplicationContext 應(yīng)該在應(yīng)用程序生命周期的驅(qū)動(dòng)下在關(guān)閉時(shí)處理其所有單例。
出于同樣的目的,Spring 管理的bean 也可以實(shí)現(xiàn) JavaAutoCloseable 接口。 實(shí)現(xiàn)接口的替代方法是指定自定義的 destroy 方法,例如在 XML bean定義 中。

有關(guān)所有 bean生命周期 方法的列表,請(qǐng)參見 BeanFactory javadocs。

destroy

由包含 BeanFactory 的銷毀 bean 調(diào)用。
@throws 在關(guān)閉錯(cuò)誤的情況下發(fā)生異常。 異常將被記錄,但不會(huì)重新拋出以允許其他bean也釋放其資源。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 2.1 我們的理念是:讓別人為你服務(wù) IoC是隨著近年來輕量級(jí)容器(Lightweight Container)的...
    好好學(xué)習(xí)Sun閱讀 2,876評(píng)論 0 11
  • 25個(gè)經(jīng)典的Spring面試問答 本人收集了一些在大家在面試時(shí)被經(jīng)常問及的關(guān)于Spring的主要問題,這些問題有可...
    殺小賊閱讀 777評(píng)論 0 2
  • 說明:本文主要內(nèi)容來自慕課網(wǎng)。配合視頻食用口味更佳。主要是順著已經(jīng)學(xué)習(xí)的視頻順序總結(jié)一遍,以深化理解和方便日后復(fù)習(xí)...
    stoneyang94閱讀 899評(píng)論 3 5
  • 參考W3C Spring教程 Spring致力于J2EE應(yīng)用的各種解決方案,而不僅僅專注于某一層解決方案??梢哉fS...
    王偵閱讀 1,234評(píng)論 0 6
  • 這世間所有最深的真情,都源自懂得。有緣相知,真心相伴,靈魂便有了交集。 懂得,是心靈的交匯,是一種心語;相知的兩個(gè)...
    longouxiangai閱讀 406評(píng)論 1 0

友情鏈接更多精彩內(nèi)容