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.

Leave a Comment