ObjectProvider stream consistently includes beans from parent context

Issue: SPR-17356
This commit is contained in:
Juergen Hoeller
2018-10-09 23:14:19 +02:00
parent 83909e6e1e
commit 44afed426a
2 changed files with 9 additions and 5 deletions

View File

@@ -225,12 +225,12 @@ public interface BeanFactory {
* Note that collection types are not supported here, in contrast to reflective
* injection points. For programmatically retrieving a list of beans matching a
* specific type, specify the actual bean type as an argument here and subsequently
* use {@link ObjectProvider#toList()} or its lazy streaming/iteration options.
* use {@link ObjectProvider#orderedStream()} or its lazy streaming/iteration options.
* @return a corresponding provider handle
* @since 5.1
* @see ObjectProvider#stream()
* @see ObjectProvider#iterator()
* @see ObjectProvider#toList()
* @see ObjectProvider#stream()
* @see ObjectProvider#orderedStream()
*/
<T> ObjectProvider<T> getBeanProvider(ResolvableType requiredType);

View File

@@ -382,13 +382,13 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
}
@Override
public Stream<T> stream() {
return Arrays.stream(getBeanNamesForType(requiredType))
return Arrays.stream(getBeanNamesForTypedStream(requiredType))
.map(name -> (T) getBean(name))
.filter(bean -> !(bean instanceof NullBean));
}
@Override
public Stream<T> orderedStream() {
String[] beanNames = getBeanNamesForType(requiredType);
String[] beanNames = getBeanNamesForTypedStream(requiredType);
Map<String, T> matchingBeans = new LinkedHashMap<>(beanNames.length);
for (String beanName : beanNames) {
Object beanInstance = getBean(beanName);
@@ -424,6 +424,10 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
return null;
}
private String[] getBeanNamesForTypedStream(ResolvableType requiredType) {
return BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this, requiredType);
}
//---------------------------------------------------------------------
// Implementation of ListableBeanFactory interface