DestructionAwareBeanPostProcessor class abstract
A BeanPostProcessor that is also called before each bean is destroyed.
Use it to release, in one place, something that many beans hold
without each declaring a destroy callback: closing every sink, ending
every subscription a framework added. It runs before the bean's own
@PreDestroy and destroy callbacks. For one bean, a @PreDestroy
method is simpler.
// Close every bean that is a Sink, when the context closes.
class ClosingPostProcessor extends DestructionAwareBeanPostProcessor {
@override
bool requiresDestruction(Object bean) => bean is Sink<Object?>;
@override
void postProcessBeforeDestruction(Object bean, String beanName) =>
(bean as Sink<Object?>).close();
}
Spring (Java):
class ClosingPostProcessor implements DestructionAwareBeanPostProcessor {
@Override
public boolean requiresDestruction(Object bean) {
return bean instanceof AutoCloseable;
}
@Override
public void postProcessBeforeDestruction(Object bean, String name)
throws Exception {
((AutoCloseable) bean).close();
}
}
- Inheritance
-
- Object
- BeanPostProcessor
- DestructionAwareBeanPostProcessor
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
postProcessAfterInitialization(
Object bean, String beanName) → Object -
Called for each new bean after its init callbacks. The returned
object (a proxy, say) is what the container exposes and injects.
Also applied to
FactoryBeanproducts.inherited -
postProcessBeforeDestruction(
Object bean, String beanName) → void -
Called with the exposed bean (the one others received) before its
@PreDestroy,DisposableBean.destroyand destroy-method callbacks run. Errors are logged and collected; they do not stop the shutdown. -
postProcessBeforeInitialization(
Object bean, String beanName) → Object -
Called for each new bean after injection and the aware callbacks,
before the init callbacks (
@PostConstruct,afterPropertiesSet, init method). Returns the object to go on with, usuallybeanitself.inherited -
requiresDestruction(
Object bean) → bool -
Whether
beanneeds postProcessBeforeDestruction;trueby default. Returningfalselets the container skip tracking beans that have no destroy callbacks of their own. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited