Avoid early FactoryBean instantiation for type-based retrieval with includeNonSingletons=false and allowEagerInit=true #34710
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
type: enhancement
A general enhancement
Milestone
As indicated by two recent Boot issues (spring-projects/spring-boot#44988,
spring-projects/spring-boot#44873),
getBeanNamesForType
withincludeNonSingletons=false
butallowEagerInit=true
(as used by Boot for DataSource retrieval recently) has the unfortunate side effect of initializingFactoryBean
instances early for aFactoryBean.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 thefactoryBeanObjectType
attribute to kick in, avoiding the need to initialize theFactoryBean
instance early if the type does not match even if we have to check the singleton status.The text was updated successfully, but these errors were encountered: