Interface DestructionAwareBeanPostProcessor
- All Superinterfaces:
BeanPostProcessor
- All Known Implementing Classes:
CommonAnnotationBeanPostProcessor,InitDestroyAnnotationBeanPostProcessor,PersistenceAnnotationBeanPostProcessor,ScheduledAnnotationBeanPostProcessor,SimplePortletPostProcessor,SimpleServletPostProcessor
public interface DestructionAwareBeanPostProcessor extends BeanPostProcessor
Subinterface ofBeanPostProcessorthat adds a before-destruction callback.The typical usage will be to invoke custom destruction callbacks on specific bean types, matching corresponding initialization callbacks.
- Since:
- 1.0.1
- Author:
- Juergen Hoeller
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidpostProcessBeforeDestruction(Object bean, String beanName)Apply this BeanPostProcessor to the given bean instance before its destruction, e.g.booleanrequiresDestruction(Object bean)Determine whether the given bean instance requires destruction by this post-processor.Methods inherited from interface org.springframework.beans.factory.config.BeanPostProcessor
postProcessAfterInitialization, postProcessBeforeInitialization
Method Detail
postProcessBeforeDestruction
void postProcessBeforeDestruction(Object bean, String beanName) throws BeansException
Apply this BeanPostProcessor to the given bean instance before its destruction, e.g. invoking custom destruction callbacks.Like DisposableBean's
destroyand a custom destroy method, this callback will only apply to beans which the container fully manages the lifecycle for. This is usually the case for singletons and scoped beans.- Parameters:
bean- the bean instance to be destroyedbeanName- the name of the bean- Throws:
BeansException- in case of errors- See Also:
DisposableBean.destroy(),AbstractBeanDefinition.setDestroyMethodName(String)
requiresDestruction
boolean requiresDestruction(Object bean)
Determine whether the given bean instance requires destruction by this post-processor.NOTE: Even as a late addition, this method has been introduced on
DestructionAwareBeanPostProcessoritself instead of on a SmartDABPP subinterface. This allows existingDestructionAwareBeanPostProcessorimplementations to easily providerequiresDestructionlogic while retaining compatibility with Spring <4.3, and it is also an easier onramp to declaringrequiresDestructionas a Java 8 default method in Spring 5.If an implementation of
DestructionAwareBeanPostProcessordoes not provide a concrete implementation of this method, Spring's invocation mechanism silently assumes a method returningtrue(the effective default before 4.3, and the to-be-default in the Java 8 method in Spring 5).- Parameters:
bean- the bean instance to check- Returns:
trueifpostProcessBeforeDestruction(java.lang.Object, java.lang.String)is supposed to be called for this bean instance eventually, orfalseif not needed- Since:
- 4.3