-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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 autowiring of empty collection in @Bean method parameters using java.util.Optional [SPR-9132] #13771
Comments
Christopher Smith commented I appear not to have permission to link to issue #11443, which addresses a similar concern with field injection. This issue is directed at the new
|
Chris Beams commented Hi Christopher, You're correct that this represents a gap in support for autowired Also, the potential solutions here aren't great. So, given the reasons above combined with the fact that a reasonable (if somewhat inelegant for your purposes) workaround does exist, I'm leaving this open but moving it to the General Backlog where it can wait for further demand, e.g. votes and substantive comments. If we see a considerable number of folks wanting and needing this, we can revisit. Thanks for taking the time in any case! Chris |
Chris Beams commented One additional option to consider here would be an attribute to the
This would then apply to both the |
Michael Pellaton commented We ran into this problem when we tried to declare a Netty ChannelGroup (a thread safe subtype of Set) as spring bean. |
Eirik Lygre commented We totally need this :-) Our application allows the customer to enable or disable various services. Other parts of the system then depends on those when creating higher-level services. Being able to mark parameters as optional would greatly simplify the code. Also, while the suggested
|
Christopher Smith commented As a revisit to this issue, what about just permitting |
Eirik Lygre commented I'm not quite sure where the Another option (hah!) would be to allow/use java.util.Optional. This will not really help us right now (we're on java 7), but it would be yet another reason to move forward. |
Christopher Smith commented
|
Ittai Zeidman commented I actually have a similar demand but for all parameters not only collections. I'd like to get the "required = false" semantics on method parameters in |
Eirik Lygre commented I very much agree, and I think I automatically assumed this issue covered both. I see now that it didn't, but second the idea that it should! For a
|
Juergen Hoeller commented Note that basic support for Juergen |
Ittai Zeidman commented
|
Juergen Hoeller commented According to the new unit tests, this works fine in the 4.1.x line already, and is in line with our general Supporting other ways of expressing optionality is worth considering - but let's do this in a separate JIRA issue for each specific style please. Juergen |
Christopher Smith opened SPR-9132 and commented
The autowire semantics for collection types assume that at least one matching bean will be found to be injected. The new
@Configuration
syntax with parameter injection, however, does not have analog to@Autowired
's required=false. Changing to field injection is an inelegant workaround, and it would be cleaner to have an@AllowEmpty
or similar parameter annotation for the new syntax.Affects: 3.1.1
Issue Links:
@Inject
(a la@Autowired
's required=false)Referenced from: commits 7d22315
4 votes, 6 watchers
The text was updated successfully, but these errors were encountered: