Skip to content

Support dynamic bean lookup a la CDI's Instance type [SPR-13132] #17723

Open
@spring-projects-issues

Description

@spring-projects-issues

Thomas Darimont opened SPR-13132 and commented

It would be helpful to be able to dynamically query an application context for beans that match a specific type and or are annotated with some specific qualifier annotations.

CDI offers support for this via javax.enterprise.inject.Instance. Currently the application context only offers to query beans by type. It would be great if we could support dynamic bean lookups via Instance<T> backed by the BeanRegistry.

I did a quick PoC here.
The basic idea is to provide a custom AutowireCandidateResolver that detects Instance<T> autowire targets, identifies the actual target bean type and provides some kind of Instance adapter which performs the actual bean lookup.


Reference URL: https://github.com/thomasdarimont/spring-boot-cdi-instance-example/blob/master/src/test/java/demo/SimpleCdiInstanceAdapterTests.java#L73

Issue Links:

3 votes, 7 watchers

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions