Skip to content

Introduce API to initialize BeanFactory before singleton instantiation #32836

Closed
@sbrannen

Description

@sbrannen

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 implements LoadTimeWeaverAware (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 before ConfigurableListableBeanFactory's preInstantiateSingletons() 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 the BeanFactory before the preInstantiateSingletons() phase (and possibly before LoadTimeWeaverAware components are initialized).

Proposal

@jhoeller has proposed a new BeanFactoryInitializer interface with an initializeBeanFactory(ConfigurableListableBeanFactory) callback, and we will investigate our options in the Spring Framework 6.2 M3 time frame.

Related Issues

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions