tags:

views:

1486

answers:

1

Is there a way to write a Spring bean in XML so that it uses constructor injection when that constructor has a varargs parameter type? IE, is there a way to specify an array the way you can specify a list?

For instance:

class MyClass {
    MyClass(String... args) {
        // rest omitted
    }
}
+12  A: 

since args is an array of String you can use <list>:

 <bean name="myBean" class="MyClass">
    <constructor-arg>
        <list>
            <value>111</value>
            <value>222</value>
            <value>333</value>
            <value>444</value>
        </list>
    </constructor-arg>
</bean>
dfa