Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jhoeller opened this issue Apr 3, 2025 · 0 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@jhoeller
Copy link
Contributor

jhoeller commented Apr 3, 2025

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.

@jhoeller jhoeller added in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement labels Apr 3, 2025
@jhoeller jhoeller added this to the 6.2.6 milestone Apr 3, 2025
@jhoeller jhoeller self-assigned this Apr 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant