-
Notifications
You must be signed in to change notification settings - Fork 38.5k
ObjectProvider iterable/stream access for "beans of type" resolution in @Bean methods [SPR-11419] #16046
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
Comments
Juergen Hoeller commented This feature turns out to be rather involved, so I'm moving it to the 4.1 timeframe. Even now, we don't support individual nulls or empty collections for That said, the prototype indicated a general inconsistency in our factory method resolution algorithm which I am fixing for 4.0.2 and 3.2.8, even if hardly anybody will have noticed that inconsistency before. Juergen |
Christopher Smith commented I was looking through back issues before a feature request, and I wanted to note that the description of current behavior is inaccurate; instead of injecting an empty collection, the container doesn't inject anything at all. (You can manually initialize to |
Christopher Smith commented Just ran across this issue exactly as described. I can use an |
Juergen Hoeller commented While we're not going to accept empty collection injection by default (so the related #19901 is to be rejected), we have a new way of collection-style access in 5.1 which I'm repurposing this ticket for:
As a consequence, my recommendation is to declare such injection points as |
Caleb Cushing commented How easy is it to hand create an |
Juergen Hoeller commented Admittedly, the recommendation above is primarily for typical configuration needs within configuration classes where the entire model is quite Spring-specific in any case, as well as for programmatic access where the interaction is also with Spring-specific APIs. I expect this to be used in Spring Boot and Spring Data, for example. For autowiring purposes, aside from That said, we could support |
Caleb Cushing commented
I didn't even know doing this was legal... in part due to my using the Spring 4.x no annotation constructor syntax. Pretty sure that doesn't allow 2 constructors?
only problem I see with stream.collect(Collections.toList()) ... list.stream()... in most cases. I'm not opposed to having spring dependencies in my class, just prefer to keep it's public api free of them... I wonder if perhaps an annotation could be added, or used to change the behavior. like the new |
Juergen Hoeller commented Actually, there's still an opportunity to allow empty collection injection for the fallback constructor case, in particular a single constructor scenario. I'll give that a try as well, reopening #19901 along those lines if it works out. |
Oliver Drotbohm opened SPR-11419 and commented
In JavaConfig you can currently use an
@Autowired(required = false) List<MyComponent> myComponents
field to access all beans of a given type to potentially hand them into a component manually instantiated in an@Bean
method.That said, it would be nice if this pattern could be used at the
@Bean
method level directly such as:This currently throws an exception if not bean of type
MyComponent
can be found but could just fall back to an empty list, which is what you get with the field based approach currently.Affects: 4.0.1
Issue Links:
0 votes, 5 watchers
The text was updated successfully, but these errors were encountered: