Results 1 to 6 of 6

Thread: How to replace placeholders in entire properties file ?

  1. #1
    Join Date
    Jul 2006
    Posts
    2

    Default How to replace placeholders in entire properties file ?

    Hi,

    I have a normal PropertyPlaceholderConfigurer.
    I'd love to be able to call PropertyPlaceholderConfigurer.getProperties() and
    have it return the entire set of keys, as if it were java.util.Properties.

    Is there any way of doing this ?

    If I had a static set of properties in my "TestSpring.properties" file, then I could
    just individually inject them into various object.

    But the user will be able to add arbitrary keys into TestSpring.properties.
    So I need to enumerate all keys in the property file, and get Spring to
    replace the placeholders.

    Any ideas ?

    cheers,
    Owen

  2. #2
    Join Date
    Dec 2005
    Posts
    269

    Default

    any examples?

    I didn't understand a thing!

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

    Default

    A PropertiesFactoryBean will return a Properties object given a properties file. Just pass it the same file you pass your PropertiesPlaceholderConfigurer.
    Bill

  4. #4
    Join Date
    Jul 2006
    Posts
    2

    Default

    Hi,

    thanks for the replies... sorry, I didn't explain myself properly.
    I basically want to have placeholders within my property files....
    and have Spring inject a java.util.Properties instance into a class.
    I've tried this approach below, but when I iterate through the java.utils.Properties object that is passed to "DisplayProps".... the values of "jdbc.link.url" and "jdbc.other.url" are not replaced, ie. I get the placeholders not the values.

    regards,
    Owen

    Code:
    # properties
    jdbc.base.url=jdbc:oracle:thin:@127.0.0.1:1521:MYSID
    jdbc.link.url=${jdbc.base.url}
    jdbc.other.url=${jdbc.base.url}
    
    # bean definitions
    <beans>
    	<bean id="props" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
    		<property name="location" value="classpath:TestSpring.properties"/>
    	</bean>
    
    	<bean id="DisplayProps" class="DisplayProps">
              <property name="properties" ref="props"/>
    	</bean>
    </beans>

  5. #5
    Join Date
    Nov 2005
    Location
    India
    Posts
    16

    Arrow

    create a custom bean with gettter and setter methods of Properties objects

    and in bean configuration file

    <bean name="/" >

    <props>
    <property ="" />

    </props>
    </bean>

    get Bean and get properties with the getter of Bean you have the java.util.Properties...

  6. #6
    Join Date
    Dec 2005
    Posts
    269

    Default

    you can use the MessageSource (or alike) from the ApplicationContext.
    AFAIK, it provides a store for the prop files and does all operations with them, like picking a file based on a locale, and fills the placeholders.

Posting Permissions

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