spring-framework
spring-framework copied to clipboard
Harmonize invocation of init & destroy methods
Follow-up of #28151 and #28013. InitDestroyAnnotationBeanPostProcessor
is now doing two different things, depending in which mode it runs.
With the regular runtime, a bean is scanned and its init & destroy methods are identified and registered in the bean definition as "externally managed". That means that the core container should not invoke them if they happen to be registered on the bean definition itself. When the post-processor runs, it invokes them.
With AOT, the first bit is done (as part of the MergedBeanDefinitionPostProcessor
callback), and then we register the same methods on the bean definition but as "regular methods" this time, merging with the ones that would have been registered already. AOT does not contribute InitDestroyAnnotationBeanPostProcessor
so it does not run and the core container invokes all the init/destroy methods.
While it wasn't possible to register multiple methods before #28013, we now have the capability to make sure the post-processor is invoking those methods consistently. One caveat is that the post processor keeps Method
reference whereas the core container contains method names, assuming they're no arg methods. Another slightly weird behavior is that the contribute
part of InitDestroyAnnotationBeanPostProcessor
mutates the given RootBeanDefinition
and returns a null
contribution (as no code is really required since it instuments a regular feature of the bean definition).
This issue is about researching how we could make sure both processing are using the same path, ideally so that InitDestroyAnnotationBeanPostProcessor
does not have to do anything AOT-related since invoking init & destroy methods is a core feature of the core container.