Description
Edward Sargisson opened SPR-12855 and commented
The docs say that a top-level bean may implement Lifecycle and have its start method called at startup.
Using such a bean with XmlWebApplicationContext does not have its start method called. Only a bean that implements SmartLifecycle does.
The defects appears to be that FrameworkServlet.configureAndRefreshWebApplicationContext only calls refresh on the web application context. It only ever calls refresh(). This means that the DefaultLifecycleProcessor ends up calling startBeans(autoStartupOnly=true).
In startBeans the following check means that only SmartLifecycle beans are added to the phases collection (and then started).
if (!autoStartupOnly || (bean instanceof SmartLifecycle && ((SmartLifecycle) bean).isAutoStartup()))
I found this in 4.0.5 but a check of the source on github suggests it's still there.
If there are other code paths that result in DefaultLifecycleProcessor.start() being called I couldn't find them.
Workaround
Implement SmartLifecycle instead of Lifecycle.
Affects: 3.2.13, 4.0.5
Backported to: 3.2.14