ScheduledBeanLazyInitializationExcludeFilter
is auto-configured even when annotation-based scheduled has not been enabled
#33276
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR makes the exposure of
ScheduledBeanLazyInitializationExcludeFilter
conditional on the annotation@EnableScheduling
.When the property
spring.main.lazy-initialization
is set totrue
, theLazyInitializationBeanFactoryPostProcessor
currently applies theScheduledBeanLazyInitializationExcludeFilter
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.