Allow to use @Named annotation without having to set the bean as @Primary

This commit is contained in:
Leandro Glossman
2016-07-05 16:18:20 -03:00
committed by Dave Syer
parent afcc7dc371
commit 4597ba5af4

View File

@@ -110,8 +110,14 @@ public class SpringModule implements Module {
@Override
public Object get() {
if (this.result == null) {
String[] names = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this.beanFactory, this.type);
if (names.length == 1) {
String[] named = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this.beanFactory, this.type);
List<String> names = new ArrayList<>(named.length);
for (String name : named) {
if (name.equals(this.name)) names.add(name);
}
if (names.size() == 1) {
this.result = this.beanFactory.getBean(this.name, this.type);
}
else {