Defining a list in a Spring application context file

后端 未结 4 1907
傲寒
傲寒 2021-01-06 18:09

Can you create a List in a Spring application-context.xml file without using the element?

I have a bean whose constructor takes a Col

相关标签:
4条回答
  • 2021-01-06 18:48
    <bean name="myBean" class="com.company.MyClass">
      <constructor-arg>
        <bean class="org.springframework.util.StringUtils" factory-method="commaDelimitedListToSet">
            <constructor-arg type="java.lang.String" value="${the.value}"/>
        </bean>
      </constructor-arg>
    </bean>
    
    0 讨论(0)
  • 2021-01-06 18:51

    This works. You can use SPEL.

    In the bean config,

    <property name="collection" value="#{{'item1','item2','item3'}}"/>
    
    0 讨论(0)
  • 2021-01-06 19:02

    A possible solution for your problem is to pass a single string to your constructor and then parse the list inside the constructor using String.split().

    0 讨论(0)
  • 2021-01-06 19:08

    I don't believe so, but you could have a constructor that built the list from a string.

    (Actually, not entirely sure I'm correct--you could probably play significant games with custom placeholder configurators, although whether or not you should is probably debatable :)

    0 讨论(0)
提交回复
热议问题