-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Accept empty Collection<Component> injection for single constructor scenarios [SPR-15338] #19901
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 turns out to be quite involved since collections may consist of beans as elements or be beans themselves (typically beans of type I'm afraid we'll have to leave this as-is for 5.0, just allowing for individual optionality markers for particular collection arguments (e.g. |
Caleb Cushing commented IIRC one of my issues, that I don't seem to have documented was actually because I had to use setter injection instead of constructor injection, not sure what I tried there though. thought, perhaps this could be solved by some sort of "DefaultForMissingBeanCollection" (maybe an argument annotation?, or just I've no need for a solution in 5.0 specifically, thanks for looking into it . |
Juergen Hoeller commented This is effectively superseded by #16046 now, in favor of iterable/stream-style access via |
Juergen Hoeller commented As mentioned on #16046, a fallback to an empty (but mutable) The limitations are that this only works for constructor and factory method arguments in the unique-constructor / unique-factory-method case where we would otherwise be unable to construct an instance at all. With overloads, we still resort to backing out of resolution with |
Caleb Cushing opened SPR-15338 and commented
So I was going to do this
with the production profile this should have a bean, but in development it does not have any. I was expecting Spring to hand me an empty collection, but instead it handed me an exception.
I'm processing it as such, or maybe a stream later, we'll see.
Maybe this behavior could change in Spring 5, I could see if you annotated the collection with
@Required
to still require a bean, but to me in general, a collection should not be null, and generally should not be required to have elements. Your opinion may differ.Affects: 4.3.7
Issue Links:
@Bean
methods@Autowired
(required=false) at parameter level, as an alternative to java.util.Optional@Qualifier
works with HashMap but not with MapReferenced from: commits spring-projects/spring-boot@c98bb40
The text was updated successfully, but these errors were encountered: