-
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
@Autowired does not work for target bean of type Collection [SPR-12180] #16794
Comments
Juergen Hoeller commented I'm afraid this is by design: Regular autowiring treats collections and map specifically - as collections of target beans, in the case of maps with the target bean names as keys. Injecting a target bean which is a collection or map itself doesn't work with Note that injecting a target bean which holds a nested collection or map - e.g. defined as an inner bean for a list property of an outer bean - works just fine with That said, we can consider a specific flag on Hope that helps for the time being, Juergen |
Christopher Smith commented I understand that the autowiring does treat collection types that way, but I don't see why it normatively should. The behavior that would surprise me least for this type of injection would be:
It would also potentially be useful to be able to fold collections; my use case involves a list of |
Christopher Smith commented I have another use case where this limitation is causing problems. I have a number of AWS keypairs that are injected as collection into an |
Christopher Smith commented I am really looking forward to the API conveniences in 4.3. Are the new semantics of collection injection documented yet? |
Juergen Hoeller commented Not yet. In summary, I would not recommend arrangements that play with those semantics in too subtle a fashion. The main goal is to keep existing contexts working while also allowing straightforward arrangements that rely on the new variants. In case of ambiguities, please use qualifiers... Feel free to play with it in the latest Juergen |
Workaround. |
If you have shown interest in this issue, you may also be interested in the following which is currently scheduled for inclusion in Spring Framework 6.1. |
Claudio D'Angelo opened SPR-12180 and commented
I have a controller class with a field
List<String>
autowired:In my configuration I've wrote:
When the application start spring throw an error:
In the
DefaultListableBeanFactory
the search for autowire candidate get the collection type and use this type to search the candidate:I think that the system must search candidate for the
type
variable and not forelementType
. In my issue theelementType
isString
notjava.util.List
.Affects: 3.2.11
Issue Links:
@Produces
(for Array/Map/Collection inject) ("is duplicated by")@Autowired-like
self injection@Named
0 votes, 8 watchers
The text was updated successfully, but these errors were encountered: