Skip to content

Commit b6f6949

Browse files
committed
NoUniqueBeanDefinitionException exposes beanNamesFound collection
Issue: SPR-13968
1 parent 68f6cf9 commit b6f6949

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/NoUniqueBeanDefinitionException.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -34,6 +34,8 @@ public class NoUniqueBeanDefinitionException extends NoSuchBeanDefinitionExcepti
3434

3535
private int numberOfBeansFound;
3636

37+
private Collection<String> beanNamesFound;
38+
3739

3840
/**
3941
* Create a new {@code NoUniqueBeanDefinitionException}.
@@ -54,6 +56,7 @@ public NoUniqueBeanDefinitionException(Class<?> type, int numberOfBeansFound, St
5456
public NoUniqueBeanDefinitionException(Class<?> type, Collection<String> beanNamesFound) {
5557
this(type, beanNamesFound.size(), "expected single matching bean but found " + beanNamesFound.size() + ": " +
5658
StringUtils.collectionToCommaDelimitedString(beanNamesFound));
59+
this.beanNamesFound = beanNamesFound;
5760
}
5861

5962
/**
@@ -76,4 +79,14 @@ public int getNumberOfBeansFound() {
7679
return this.numberOfBeansFound;
7780
}
7881

82+
/**
83+
* Return the names of all beans found when only one matching bean was expected.
84+
* Note that this may be {@code null} if not specified at construction time.
85+
* @since 4.3
86+
* @see #getBeanType()
87+
*/
88+
public Collection<String> getBeanNamesFound() {
89+
return this.beanNamesFound;
90+
}
91+
7992
}

0 commit comments

Comments
 (0)