Announcement Announcement Module
Collapse
No announcement yet.
How to replace placeholders in entire properties file ? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    any examples?

    I didn't understand a thing!

    Comment


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

      Comment


      • #4
        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>

        Comment


        • #5
          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...

          Comment


          • #6
            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.

            Comment

            Working...
            X