reading a dynamic property list into a spring managed bean reading a dynamic property list into a spring managed bean spring spring

reading a dynamic property list into a spring managed bean


You may want to take a look at Spring's StringUtils class. It has a number of useful methods to convert a comma separated list to a Set or a String array. You can use any of these utility methods, using Spring's factory-method framework, to inject a parsed value into your bean. Here is an example:

<property name="machines">    <bean class="org.springframework.util.StringUtils" factory-method="commaDelimitedListToSet">        <constructor-arg type="java.lang.String" value="${machines}"/>    </bean></property>

In this example, the value for 'machines' is loaded from the properties file.

If an existing utility method does not meet your needs, it is pretty straightforward to create your own. This technique allows you to execute any static utility method.


Spring EL makes easier. Java:

List <String> machines;

Context:

<property name="machines" value="#{T(java.util.Arrays).asList('${machines}')}"/>


If you make the property "machines" a String array, then spring will do it automatically for you

machines=B,C,D<property name="machines" value="${machines}"/>public void setMachines(String[] test) {