Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow filtering bean instances returned by ObjectProvider#stream() #34318

Closed
odrotbohm opened this issue Jan 24, 2025 · 5 comments
Closed

Allow filtering bean instances returned by ObjectProvider#stream() #34318

odrotbohm opened this issue Jan 24, 2025 · 5 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@odrotbohm
Copy link
Member

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.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jan 24, 2025
@snicoll snicoll changed the title Allow filtering bean instances returned by ObjectProvider.stream() Allow filtering bean instances returned by ObjectProvider#stream() Jan 28, 2025
@snicoll snicoll added the in: core Issues in core modules (aop, beans, core, context, expression) label Jan 28, 2025
@snicoll
Copy link
Member

snicoll commented Jan 28, 2025

This seems to have some connection with #34203

@jhoeller jhoeller added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jan 28, 2025
@jhoeller jhoeller added this to the 6.2.x milestone Jan 28, 2025
@jhoeller jhoeller self-assigned this Jan 28, 2025
@jhoeller
Copy link
Contributor

jhoeller commented Feb 3, 2025

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?

@odrotbohm
Copy link
Member Author

It would, indeed.

@jhoeller jhoeller modified the milestones: 6.2.x, 6.2.3 Feb 3, 2025
@odrotbohm
Copy link
Member Author

Would that need to be forward-ported to 7.0?

@snicoll
Copy link
Member

snicoll commented Feb 13, 2025

It has been.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants