micronaut-core
micronaut-core copied to clipboard
Multiple iterable beans not resulting in `NonUniqueBeanException` on `getBean`
Expected Behavior
Expecting thrown NonUniqueBeanException
.
Actual Behaviour
Looks like in DefaultApplicationContext
there is some logic that is selecting the first one:
@Override
protected <T> BeanDefinition<T> findConcreteCandidate(Class<T> beanType, Qualifier<T> qualifier, Collection<BeanDefinition<T>> candidates) {
if (!(qualifier instanceof Named)) {
return super.findConcreteCandidate(beanType, qualifier, candidates);
}
for (BeanDefinition<T> candidate : candidates) {
if (!candidate.isIterable()) {
return super.findConcreteCandidate(beanType, qualifier, candidates);
}
}
for (BeanDefinition<T> candidate : candidates) {
if (candidate instanceof BeanDefinitionDelegate) {
Qualifier<T> delegateQualifier = candidate.resolveDynamicQualifier();
if (delegateQualifier != null && delegateQualifier.equals(qualifier)) {
return candidate; // ???
}
}
}
return super.findConcreteCandidate(beanType, qualifier, candidates);
}
I think the correct way is to filter them, not returning the first that is matching.
Steps To Reproduce
No response
Environment Information
No response
Example Application
No response
Version
3.6