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
的一个子接口。
文档
要在销毁时释放资源的 bean
所实现的接口。BeanFactory
将在 有作用域的bean
单独销毁时调用 destroy
方法。 一个 org.springframework.context.ApplicationContext
应该在应用程序生命周期的驱动下在关闭时处理其所有单例。
出于同样的目的,Spring
管理的bean
也可以实现 Java
的 AutoCloseable
接口。 实现接口的替代方法是指定自定义的 destroy
方法,例如在 XML bean定义
中。
有关所有 bean生命周期
方法的列表,请参见 BeanFactory javadocs
。
destroy
由包含 BeanFactory
的销毁 bean
调用。
@throws
在关闭错误的情况下发生异常。 异常将被记录,但不会重新抛出以允许其他bean也释放其资源。
网友评论