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-12872] #17470

Closed
spring-projects-issues opened this issue Mar 31, 2015 · 2 comments
Closed
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Mar 31, 2015

Ivan Bovin opened SPR-12872 and commented

If we have a @Scheduled method in a @Lazy bean, it will be added to ScheduledTaskRegistrar (e.g. using a addFixedDelayTask method) but not scheduled in the taskScheduler.

Example:

@Lazy
@Component
public class SampleBean {
    @Scheduled(fixedDelay = 500)
    public void task() {
        System.out.println("-");
    }
}

Affects: 4.1.5

Issue Links:

Referenced from: commits ab478d1

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

This is unfortunately a known limitation at this point: @Scheduled only really works on non-lazy singletons. We'll revisit this for 4.2.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

As of 4.3 RC2, ScheduledAnnotationBeanPostProcessor features a revised registration mechanism capable of tracking individual bean instances, both on creation for beans of any scope and on destruction of each individual bean. In other words, @Scheduled works on any Spring-managed bean now, not just on non-lazy singleton beans anymore.

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: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants