The implementations of ObjectProvider.stream() look up all bean names for the type referenced and subsequently look up the bean instance itself. This means that a call to ….stream() ultimately causes all bean instances to be initialized. It would be nice if there was a way to be selective about which of those instances I want to get by being able to filter on the bean name before instantiation.
My particular use case is to exclude beans of a particular type, so the filter being a BiPredicate<String, Class<?>> would prevent my code from having to obtain a reference to a BeanFactory to obtain the bean definition's type. That said, a simple stream(Predicate<String> beanNameFilter) would work as well.
Comment From: snicoll
This seems to have some connection with https://github.com/spring-projects/spring-framework/issues/34203
Comment From: jhoeller
Design-wise, filtering just by type is actually more attractive than filtering by bean name (since bean names have no conceptual exposure in the ObjectProvider API otherwise). @odrotbohm would a plain Predicate<Class<?>> do the job for you as well?
Comment From: odrotbohm
It would, indeed.