Skip to content
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

Closed
spring-projects-issues opened this issue Dec 3, 2009 · 5 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Dec 3, 2009

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

@spring-projects-issues
Copy link
Collaborator Author

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

@spring-projects-issues
Copy link
Collaborator Author

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.

@spring-projects-issues
Copy link
Collaborator Author

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

@spring-projects-issues
Copy link
Collaborator Author

Liu, Yinwei David commented

Thanks Juergen.

@spring-projects-issues
Copy link
Collaborator Author

Richard Levac commented

@Juergen: I know this is an old ticket but by preventing SmartLifecycle beans from being "lazy-inited" have a serious side effect on org.springframework.scheduling.quartz.SchedulerFactoryBean which implements SmartLifecycle as well. Before this code change it was possible to create SchedulerFactoryBean bean definition and init them on demand. In my case, I have several SchedulerFactoryBean def in my applicationContext.xml for various situations in my application.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants