This PR makes the exposure of ScheduledBeanLazyInitializationExcludeFilter conditional on the annotation @EnableScheduling.

When the property spring.main.lazy-initialization is set to true, the LazyInitializationBeanFactoryPostProcessor currently applies the ScheduledBeanLazyInitializationExcludeFilter to each bean definition. This is independent of whether the user has opted in to scheduling with @EnableScheduling or not.

The goal of the PR is to improve the start-up performance of applications that use lazy initialization but not scheduling. An example could be a short-lived Spring Batch app that contains multiple job beans but executes only a single job when started and exits afterwards. Such an app would not use scheduling and profits from not initializing all beans on start up.

I've assembled a toy application with a flame graph here: https://github.com/hpoettker/lazy-scheduler-demo

About 3% of the whole application run-time is spent on the ScheduledBeanLazyInitializationExcludeFilter.

The start-up time (as logged by the application) varies between runs. But on my machine it's about 0.65 seconds and reduces to 0.60 seconds when the TaskSchedulingAutoConfiguration is excluded.

Comment From: snicoll

Thanks again @hpoettker