Announcement Announcement Module
Collapse
No announcement yet.
Bean collection propertie from properties file Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Bean collection propertie from properties file

    Hello,

    I'm currently converting over our spring config file to use the context property placeholder to populate the bean properties from a properties file. eg :

    <contextroperty-placeholder location="classpath:spring.properties" />

    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
    <property name="driverClass" value="${db.class}"/>
    ....


    A few of the beans have properties that are collections, (mostly List<String>). These were previously configured via the xml collection markup <value>blah1</value><value>blah2</value><value>blah3</value>.

    I've tried putting the xml into the properties file using the normal method, but I believe this means that it skips the phase during startup where the xml is converted to a list.

    Does anyone know a way to set collection properties on beans via a properties file?

    Many thanks in advance!

    p.s sorry for the typo in the subject!

  • #2
    So I guess no-one knows a way to do this? I've been looking everywhere to no avail.. maybe I need to add a JIRA request or something?

    Comment


    • #3
      Afaik there is no out-of-the-box utility for collection handling.
      I think you have to create your own BeanPostProcessor that allows this.
      You need to define a format however, that can provide a value collection out of properties.

      Possible examples:
      Code:
      collection.1=val1
      collection.2=val2
      collection.3=val3
      or

      Code:
      collection=val1;val2;val3

      Comment


      • #4
        What I always do is have the property be a comma separated string. Then my bean setter method takes a string, but the getter returns a List<String>

        A-like so:

        public List<String> getSeedEmails() {
        return seedEmails;
        }


        public void setSeedEmails(String seedEmails) {
        String[] emails = seedEmails.split(",");
        this.seedEmails = Arrays.asList(emails);
        }

        Comment

        Working...
        X