Interface DisposableBean

All Known Implementing Classes:
AbstractBeanFactoryBasedTargetSourceCreator, AbstractEntityManagerFactoryBean, AbstractFactoryBean, AbstractJmsListeningContainer, AbstractMessageListenerContainer, AbstractPollingMessageListenerContainer, AbstractPoolingTargetSource, AbstractRequestLoggingFilter, AbstractServiceLoaderBasedFactoryBean, AnnotationMBeanExporter, BeanConfigurerSupport, CachingConnectionFactory, CharacterEncodingFilter, CommonsPool2TargetSource, CommonsRequestLoggingFilter, ConnectionFactoryInitializer, ConnectorServerFactoryBean, ContextLifecycleScheduledTaskRegistrar, CorsFilter, DataSourceInitializer, DefaultContextLoadTimeWeaver, DefaultMessageListenerContainer, DelegatingFilterProxy, EmbeddedDatabaseFactoryBean, ExecutorConfigurationSupport, ForkJoinPoolFactoryBean, FormContentFilter, ForwardedHeaderFilter, GenericFilterBean, GenericMessageEndpointManager, HiddenHttpMethodFilter, HttpComponentsClientHttpRequestFactory, JCacheManagerFactoryBean, JdkHttpClientResourceFactory, JettyResourceFactory, JmsListenerEndpointRegistry, JmsMessageEndpointManager, LazyInitTargetSourceCreator, ListFactoryBean, LocalContainerEntityManagerFactoryBean, LocalEntityManagerFactoryBean, LocalSessionFactoryBean, LocalValidatorFactoryBean, MapFactoryBean, MBeanClientInterceptor, MBeanExporter, MBeanProxyFactoryBean, MBeanServerConnectionFactoryBean, MBeanServerFactoryBean, MultipartFilter, NotificationListenerRegistrar, ObjectFactoryCreatingFactoryBean, OkHttp3ClientHttpRequestFactory, OncePerRequestFilter, OpenEntityManagerInViewFilter, OpenSessionInViewFilter, OptionalValidatorFactoryBean, ProviderCreatingFactoryBean, QuickTargetSourceCreator, ReactorNetty2ResourceFactory, ReactorResourceFactory, RelativeRedirectFilter, RequestContextFilter, ResourceAdapterFactoryBean, ResourceBundleViewResolver, ResourceUrlEncodingFilter, ScheduledAnnotationBeanPostProcessor, ScheduledExecutorFactoryBean, ScheduledTaskRegistrar, SchedulerFactoryBean, ScriptFactoryPostProcessor, ServerHttpObservationFilter, ServiceFactoryBean, ServiceListFactoryBean, ServiceLoaderFactoryBean, ServletContextRequestLoggingFilter, ServletContextScope, ServletWrappingController, SetFactoryBean, ShallowEtagHeaderFilter, SimpleMessageListenerContainer, SimpleThreadPoolTaskExecutor, SingleConnectionDataSource, SingleConnectionFactory, SingleConnectionFactory, SortedResourcesFactoryBean, TaskExecutorFactoryBean, ThreadLocalTargetSource, ThreadPoolExecutorFactoryBean, ThreadPoolTaskExecutor, ThreadPoolTaskScheduler, XmlViewResolver

public interface DisposableBean
Interface to be implemented by beans that want to release resources on destruction. A BeanFactory will invoke the destroy method on individual destruction of a scoped bean. An ApplicationContext is supposed to dispose all of its singletons on shutdown, driven by the application lifecycle.

A Spring-managed bean may also implement Java's 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 BeanFactory javadocs.

Since:
12.08.2003
Author:
Juergen Hoeller
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Invoked by the containing BeanFactory on destruction of a bean.
  • Method Details

    • destroy

      void destroy() throws Exception
      Invoked by the containing 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.