Issue
I have a class with the following constructor:
public MyClass(Map<String s, Collection<Object>> co){
//impl
}
I need to invoke it via Spring bean's declarations. I tried to do something like this:
<bean id="toInject" class="path.toSomClass" />
<bean id="myBean" class="path.to.MyClass">
<constructor-arg>
<map>
<entry key="String"
value-ref="_WHAT_SHOULD_I_WRITE_HERE_TO_DECLARE_A_COLLECTION_FROM_THE_ONLY_toInject">
</map>
</constructor-arg>
</bean>
I'm not concerned about the type of the Collection
(It may be a List<T>
as well as Set<T>
, or anything else implementing Collection<T>
).
Solution
You can declare a <list>
element as part of the value for the entry, like this:
<bean id="myBean" class="path.to.MyClass">
<constructor-arg>
<map>
<entry key="String">
<list>
<ref bean="toInject" />
</list>
</entry>
</map>
</constructor-arg>
</bean>
Answered By - Tunaki
Answer Checked By - Marie Seifert (JavaFixing Admin)