Description
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.