Open
Description
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.
Issue Links:
- Add generics / parameterized type support to ListableBeanFactory getBeanNamesForType/getBeansOfType methods [SPR-12147] #16761 Add generics / parameterized type support to ListableBeanFactory getBeanNamesForType/getBeansOfType methods
- An ObjectFactory variant with lenient not-unique handling [SPR-13943] #18515 An ObjectFactory variant with lenient not-unique handling
- Convenient programmatic bean retrieval with qualifiers [SPR-8891] #13532 Convenient programmatic bean retrieval with qualifiers
- ObjectFactory lacks method for getting bean with specified constructor arguments [SPR-13956] #18529 ObjectFactory lacks method for getting bean with specified constructor arguments
- Ability to query an ApplicationContext for annotations on a bean [SPR-12929] #17522 Ability to query an ApplicationContext for annotations on a bean
3 votes, 7 watchers