public interface DestructionAwareBeanPostProcessor extends BeanPostProcessor
BeanPostProcessor
that adds a before-destruction callback.
The typical usage will be to invoke custom destruction callbacks on specific bean types, matching corresponding initialization callbacks.
Modifier and Type | Method and Description |
---|---|
void |
postProcessBeforeDestruction(Object bean,
String beanName)
Apply this BeanPostProcessor to the given bean instance before
its destruction.
|
boolean |
requiresDestruction(Object bean)
Determine whether the given bean instance requires destruction by this
post-processor.
|
postProcessAfterInitialization, postProcessBeforeInitialization
void postProcessBeforeDestruction(Object bean, String beanName) throws BeansException
Like DisposableBean's destroy
and a custom destroy method,
this callback just applies to singleton beans in the factory (including
inner beans).
bean
- the bean instance to be destroyedbeanName
- the name of the beanBeansException
- in case of errorsDisposableBean
,
AbstractBeanDefinition.setDestroyMethodName(java.lang.String)
boolean requiresDestruction(Object bean)
NOTE: Even as a late addition, this method has been introduced on
DestructionAwareBeanPostProcessor
itself instead of on a SmartDABPP
subinterface. This allows existing DestructionAwareBeanPostProcessor
implementations to easily provide requiresDestruction
logic while
retaining compatibility with Spring <4.3, and it is also an easier onramp to
declaring requiresDestruction
as a Java 8 default method in Spring 5.
If an implementation of DestructionAwareBeanPostProcessor
does
not provide a concrete implementation of this method, Spring's invocation
mechanism silently assumes a method returning true
(the effective
default before 4.3, and the to-be-default in the Java 8 method in Spring 5).
bean
- the bean instance to checktrue
if postProcessBeforeDestruction(java.lang.Object, java.lang.String)
is supposed to
be called for this bean instance eventually, or false
if not needed