-
Notifications
You must be signed in to change notification settings - Fork 38.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spring does not start SmartLifecycle bean if it is lazy-init [SPR-6515] #11181
Comments
Juergen Hoeller commented What would you expect to happen in such a scenario? We could initialize the SmartLifecycle bean nevertheless and start it if its isAutoStartup() method returns true. Note that the bean instance would get initialized at refresh time in any case then; so effectively, lazy-init on such a bean would be a no-op. What's the reason for defining lazy-init="true" there in the first place? If it is not supposed to have any actual effect, could you simply remove it? Juergen |
Liu, Yinwei David commented I think we need to start SmartLifecycle if its isAutoStartup() method returns true, because the bean itself requires to get started. Otherwise, other components with lower phase which implicitly depends on it may fail due to the bean was not started. Yup I just found lazy-init="true" in my test by accident, so I simply remove it. |
Juergen Hoeller commented OK, SmartLifecycle beans will get auto-started on demand now even if marked as lazy-init. As a consequence, the bean definition lazy-init flag has very limited actual effect on SmartLifecycle beans: Their bean instances will just get initialized a step later during context startup. Regular Lifecycle beans remain unaffected by this change: Their instances will be created on first user access still, since auto-startup support does not apply to them in the first place. Juergen |
Liu, Yinwei David commented Thanks Juergen. |
Richard Levac commented
Did a recent search on Google and I seems to not be the only one having this issue since this behavior has changed. Look at bug https://jira.springsource.org/browse/SPR-8285 for more details. Thanks |
Liu, Yinwei David opened SPR-6515 and commented
If one SmartLifecycle bean is * lazy-init="true"*, Spring will not auto start it during refresh and application.start()
Affects: 3.0 RC3
Issue Links:
Referenced from: commits 736c721, 93b1704
The text was updated successfully, but these errors were encountered: