Skip to content

Avoid early FactoryBean instantiation for type-based retrieval with includeNonSingletons=false and allowEagerInit=true #34710

Closed
@jhoeller

Description

@jhoeller

As indicated by two recent Boot issues (spring-projects/spring-boot#44988,
spring-projects/spring-boot#44873), getBeanNamesForType with includeNonSingletons=false but allowEagerInit=true (as used by Boot for DataSource retrieval recently) has the unfortunate side effect of initializing FactoryBean instances early for a FactoryBean.isSingleton() check even if they subsequently turn out not match the desired type.

Switching that check to type first and then singleton status (when necessary for includeNonSingletons=false) allows for type pre-determination mechanisms such as the factoryBeanObjectType attribute to kick in, avoiding the need to initialize the FactoryBean instance early if the type does not match even if we have to check the singleton status.

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