It is said in Spring javadoc, that \"Note that the Lifecycle interface is only supported on top-level singleton beans.\" Here URL
My LifecycleBeanTest.xml
d
You should use SmartLifecycle
instead of Lifecycle
. Only the former is working as you expected Lifecycle
to work. Make sure you return true in your isRunning()
implementation.
I have used SmartLifecycle
for asynchronous jobs for which it sounds like designed for. I suppose it will work for you but at the same time you may have a look at ApplicationListener
and events like ContextStoppedEvent
.