Inject array of strings to a bean in Spring

instead of <list> use

<array>
  <value>aa</value>
  <value>bb</value>
  <value>cc</value>
</array>

With Spring version 3.2.8 you can use

<constructor-arg>
    <list>
        <value>aa</value>
        <value>bb</value>
        <value>cc</value>
    </list>
</constructor-arg>

without problems.


You should use:

<constructor-arg>
    <array>
        <value>aa</value>
        <value>bb</value>
        <value>cc</value>
    </array>
</constructor-arg>

An array can contain multiple inner bean, ref, collection, or value elements. This configuration element will always result in an array, even when being defined e.g. as a value for a map with value type Object.

Also you can specify a value type which you will be passing:

<array value-type="java.lang.String">
  <value>aa</value>
  <value>bb</value>
  <value>cc</value>
</array>

value-type

The default Java type for nested values. Must be a fully qualified class name.

Tags:

Java

Spring