Class InitDestroyAnnotationBeanPostProcessor

java.lang.Object
org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor
All Implemented Interfaces:
Serializable, BeanRegistrationAotProcessor, BeanPostProcessor, DestructionAwareBeanPostProcessor, MergedBeanDefinitionPostProcessor, org.springframework.core.Ordered, org.springframework.core.PriorityOrdered

public class InitDestroyAnnotationBeanPostProcessor extends Object implements DestructionAwareBeanPostProcessor, MergedBeanDefinitionPostProcessor, BeanRegistrationAotProcessor, org.springframework.core.PriorityOrdered, Serializable
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 org.springframework.context.annotation.CommonAnnotationBeanPostProcessor supports the jakarta.annotation.PostConstruct and jakarta.annotation.PreDestroy annotations out of the box, as init annotation and destroy annotation, respectively. Furthermore, it also supports the jakarta.annotation.Resource annotation for annotation-driven injection of named beans.

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