i am trying to develop a Spring bean
like this
<bean id="id" class="java.util.ArrayList" scope='prototype'>
<constructor-arg>
<list>
<bean class='MyClass'>
<property name='id' value='1313'/>
<property name="name" value='John Lennon'/>
<property name='wifes'>
<list>
<bean class="WifeClazz">
<constructor-arg index='0' value='Cynthia Lennon'/>
<constructor-arg index='1'>
<list><value>1962</value><value>1968</value></list>
</constructor-arg>
</bean>
</list>
</property>
</bean>
</list>
</constructor-arg>
</bean>
this is just a example the WifeClazz
the name is just for the example.. have a Constructor which have a String and a series of Integers.. like this example
new WifeClazz("Cinthia Lennon",java.util.Arrays.asList(1,2,3,4,5,6,7,8));
the integers may be a severals from 1 to 10 integers.
but i think is kind of annoying do something like this
<constructor-arg index='1'>
<list>
<value>1</value>
<value>2</value>
<value>3</value>
<value>4</value>
</list>
</constructor-arg>
would be great if i could do something like this
<constructor-arg index='1'>
<value>#{T(java.util.Arrays).asList(1,2,3,4)}</value>
</constructor-arg>
but throws Exception any clue?
any help is hugely appreciate.
UPDATE
I have change my code according Edwin a something like this.
<constructor-arg index="1" type="java.util.Collection" value="#{T(java.util.Arrays).asList(1,2,3,4,5)}"/>
but throws
Caused by: java.lang.IllegalArgumentException: Final expected argument should be array type (the varargs parameter)
my target clazz is
public MyClass(final String name,final List<Integer>years){}
my resulting code
<bean id="id" class="java.util.ArrayList" scope='prototype'>
<constructor-arg>
<list>
<bean class='MyClass'>
<property name='id' value='1313'/>
<property name="name" value='John Lennon'/>
<property name='wifes'>
<list>
<bean class="WifeClazz">
<constructor-arg index='0' value='Cynthia Lennon'/>
<constructor-arg index="1" type="java.util.Collection" value="#{T(java.util.Arrays).asList(1,2,3,4,5)}"/>
</bean>
</list>
</property>
</bean>
</list>
</constructor-arg>
</bean>
this solves the trick...
<constructor-arg index='1' type="java.util.List" value="#{{1,2,3,4,5}}"/>
This works for me
<bean id="list" class="java.util.ArrayList">
<constructor-arg index="0" value="#{T(java.util.Arrays).asList(1,2,3,4,5)}"/>
</bean>
To disambiguate constructors, this also works for me
<bean id="list" class="java.util.ArrayList">
<constructor-arg type="java.util.Collection" value="#{T(java.util.Arrays).asList(1,2,3,4,5)}"/>
</bean>
You can also use a collection SPeL, like this, and avoid having to use Arrays.asList directly.
<bean id="list" class="java.util.ArrayList">
<constructor-arg type="java.util.Collection" value="#{{1,2,3,4,5}}"/>
</bean>