Results 1 to 4 of 4

Thread: initializing a bean with a list properties

  1. #1
    Join Date
    Jun 2005
    Posts
    20

    Default 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. #2
    Join Date
    Feb 2005
    Location
    Boston, MA
    Posts
    1,142

    Default Re: initializing a bean with a list properties

    Quote 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.

  3. #3
    Join Date
    Jul 2005
    Location
    Reading, UK
    Posts
    1

    Default 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.

  4. #4
    Join Date
    Feb 2005
    Location
    Boston, MA
    Posts
    1,142

    Default

    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>

Similar Threads

  1. Order of Bean definitions matters?
    By cfuser in forum Container
    Replies: 2
    Last Post: Oct 21st, 2005, 10:29 AM
  2. Spring container fails with no exception
    By naor in forum Container
    Replies: 9
    Last Post: Oct 1st, 2005, 03:39 PM
  3. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  4. could not satisfy dependencies
    By springuser in forum Container
    Replies: 4
    Last Post: Apr 26th, 2005, 01:15 PM
  5. Replies: 1
    Last Post: Apr 25th, 2005, 07:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •