Skip to content

Consistent type resolution handling for NullBean #26271

@snicoll

Description

@snicoll

When a @Bean factory returns null, a NullBean is registered in the context that's not meant to be considered when looking for a candidate by type (only a lookup by name would return it).

Unfortunately, that does not work in at least two cases:

  • org.springframework.beans.factory.config.AutowireCapableBeanFactory#resolveNamedBean will return such NullBean for the type it has been defined against
  • org.springframework.beans.factory.ListableBeanFactory#getBeanNamesForType(org.springframework.core.ResolvableType, boolean, boolean) will do that (used by Spring Boot's @ConditionalOnMissingBean.

This was original raised in spring-projects/spring-boot#24448 that contains a sample project.

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