I am very enthusiast about Spring 6.2 feaute of Bean Background Initialization implemented via @Bean
annotation.
However, I would suggest to extend it also to @Component
-scanned beans. I have an application with thousands of beans, and I am working on improving its startup time. Basically, while I have benefitted from @Bean(bootstrap = BACKGROUND)
for @Configuration
-factored bean, it is not convenient to refactor a number of @Component
beans into @Bean
beans for reasons of simplicity.
Implementing the bootstrap = BACKGROUND
attribute into @Component
and derivatives seems to me to be the next step.
Any thoughts on this?
Comment From: jhoeller
I'm afraid that we have no such plans. Component scanning is a decentralized stereotype model, concrete bootstrapping definitions would arguably not really fit there. We do actually recommend defining such beans in @Bean
methods instead.
For a large number of scanned beans, you could implement a BeanFactoryPostProcessor
that sets the backgroundInit
flag on corresponding BeanDefinition
instances based on some policy, for example based on naming or a custom annotation.