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

@Scheduled methods in @Lazy beans are not scheduled [SPR-17587] #22119

Closed
spring-projects-issues opened this issue Dec 10, 2018 · 1 comment
Closed
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: declined A suggestion or change that we don't feel we should currently apply

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Dec 10, 2018

Silvio Assunção Junior opened SPR-17587 and commented

The issue #17470 was not resolved,  the problem continue

I checked the code of ScheduledAnnotationBeanPostProcessor and the tasks will registered on method postProcessAfterInitialization, but lazy Beans it is not created or initialized, than Beans with @Scheduled and @Lazy does not work correctly

The Schedule will be registered only if I will use the Bean (Force a creation)

Other guys with the same problem https://stackoverflow.com/questions/47585846/why-spring-schedule-do-not-work-with-lazy


Affects: 4.3.18

Reference URL: #17470

Issue Links:

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

This works as designed: @Scheduled will only be processed on beans while they are 'alive', i.e. after creation and before destruction of each individual bean instance. For lazy-init singletons, this lifecycle only starts once they have actually been created.

If you want a singleton bean's scheduled methods to be called from startup onwards, simply don't declare it as lazy. If you want some backend state to only be created once actually called, factor it out to a separate bean that your @Scheduled bean refers to.

@spring-projects-issues spring-projects-issues added type: bug A general bug status: declined A suggestion or change that we don't feel we should currently apply in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues removed the type: bug A general bug label Jan 12, 2019
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) status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

2 participants