Introduce API to initialize BeanFactory
before singleton instantiation
#32836
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
type: enhancement
A general enhancement
Milestone
Overview
In order to properly implement #32271, I needed a way to eagerly initialize all beans created by
@Bean
factory methods annotated with@DynamicPropertySource
before standard singleton beans are instantiated; however, Spring does not currently provide an official API that developers can implement to achieve that.As a workaround,
DynamicPropertySourceBeanInitializer
temporarily implementsLoadTimeWeaverAware
(even though it has nothing to do with load-time weaving) since doing so is currently the only way to have a component eagerly initialized beforeConfigurableListableBeanFactory
'spreInstantiateSingletons()
phase.Implementing
LoadTimeWeaverAware
to achieve this is arguably a hack, and in light of that we would like to introduce an official mechanism that allows developers to register components that are able to initialize theBeanFactory
before thepreInstantiateSingletons()
phase (and possibly beforeLoadTimeWeaverAware
components are initialized).Proposal
@jhoeller has proposed a new
BeanFactoryInitializer
interface with aninitializeBeanFactory(ConfigurableListableBeanFactory)
callback, and we will investigate our options in the Spring Framework 6.2 M3 time frame.Related Issues
DynamicPropertyRegistry
as a singleton bean in a test'sApplicationContext
#32271The text was updated successfully, but these errors were encountered: