Announcement Announcement Module
Collapse
No announcement yet.
initializing a bean with a list properties Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • initializing a bean with a list properties

    Hi,
    I want initialize a property of the type List or Map but from an external *.properties file. is this possible?

  • #2
    Re: initializing a bean with a list properties

    Originally posted by masrawi
    Hi,
    I want initialize a property of the type List or Map but from an external *.properties file. is this possible?
    Doing a Map is easy because a Properties object implements Map. You can convert a file to a Properties object using PropertiesFactoryBean

    For list you would have to create a List compatible class that could accept a Map. What would you return as each element of the list? In order to write the custom List class you'd have to figure that out.

    Comment


    • #3
      External Map property?

      Can you expand you explanation for me? I am using a PropertyOverrideConfigurer defined as follows in my web application context:
      Code:
          <bean id="overrideConfig" class="org.springframework.beans.factory.config.PropertyOverrideConfigurer">
      	    <property name="location"><value>file&#58;///mydir/myprops.properties</value></property>
          </bean>
      This works perfectly for overriding simple value properties from the external properties file. What I would like to do is override a Map property:
      Code:
          <bean id="myBean" class="mystuff.MyBean">	    	
          	<property name="myMap">
      	    	<map> 
              		<entry key="2"><value>two</value></entry>
              		<entry key="3"><value>three</value></entry>
              	</map>  	    
              </property>      	
          </bean>
      How can I define "myMap" from an external file? Any solution is welcome it doesn't have to use the PropertyOverrideConfigurer.

      Thanks.

      Comment


      • #4
        Code:
        <bean id="myBean" class="mystuff.MyBean">          
           <property name="myMap">
              <bean class="org.springframework.beans.factory.config.PropertiesFactoryBean">
               <property name="location">
                 <value>file&#58;///mydir/myprops.properties</value>
               </property>
              </bean>    
            </property>         
        </bean>

        Comment

        Working...
        X