Class InitDestroyAnnotationBeanPostProcessor

All Implemented Interfaces:
Serializable, BeanRegistrationAotProcessor, BeanPostProcessor, DestructionAwareBeanPostProcessor, MergedBeanDefinitionPostProcessor, Ordered, PriorityOrdered
Direct Known Subclasses:

BeanPostProcessor implementation that invokes annotated init and destroy methods. Allows for an annotation alternative to Spring's InitializingBean and DisposableBean callback interfaces.

The actual annotation types that this post-processor checks for can be configured through the "initAnnotationType" and "destroyAnnotationType" properties. Any custom annotation can be used, since there are no required annotation attributes.

Init and destroy annotations may be applied to methods of any visibility: public, package-protected, protected, or private. Multiple such methods may be annotated, but it is recommended to only annotate one single init method and destroy method, respectively.

Spring's CommonAnnotationBeanPostProcessor supports the PostConstruct and PreDestroy annotations out of the box, as init annotation and destroy annotation, respectively. Furthermore, it also supports the Resource annotation for annotation-driven injection of named beans.

Juergen Hoeller, Stephane Nicoll, Phillip Webb, Sam Brannen
See Also: