Skip to content

An ObjectFactory variant with lenient not-unique handling [SPR-13943] #18515

Closed

Description

@spring-projects-issues

Stéphane Nicoll opened SPR-13943 and commented

In Spring Boot it is very common to associate a bean to something if it is found in the context. If there is more than one instance but one is flagged as primary then we're fine as well. If there are more than one instance and the user did not mark a preference for one, then we don't know which one to use.

We would need a first class support of that use case, maybe based on the ObjectFactory. Something that would return the candidate bean or null if none was found.


Issue Links:

Referenced from: commits ed98393, 343bb2f

Activity

  1. spring-projects-issues commented on Feb 12, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    I've introduced a SmartObjectFactory sub-interface with getIfAvailable() and getIfUnique() variants, allowing for programmatic optionality and lenient not-unique handling.

    Juergen

  2. spring-projects-issues commented on Feb 23, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    Renamed to ObjectProvider (extends ObjectFactory), as per our discussion today.

  3. added
    type: enhancement
    in: core
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: coretype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions