Announcement Announcement Module
Collapse
No announcement yet.
How to load multiple property files using [HTML]<util:properties/>[/HTML] tag. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to load multiple property files using [HTML]<util:properties/>[/HTML] tag.

    Hi Guys,

    I am trying to load multiple properties files using <utilroperties/> tag.

    Basically I have the following setting working:

    Code:
    <bean id="applicationProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    		<property name="locations">
    			<list>
    				<value>classpath:helloWorld.properties</value>
    	<value>classpath:helloWorld-${environmentName}.properties</value>				
    			</list>
    		</property>
    		<property name="ignoreResourceNotFound" value="true" />
    		<property name="ignoreUnresolvablePlaceholders" value="true" />
    	</bean>

    I am trying to achieve the above using <utilroperties/> tag in Spring 3.0 version because I would like access the property values in my class using
    Code:
    @Value("#{applicationProperties.mediaPath}")
    I have successfully loaded one file using following code but not sure how to load more than one files.

    Code:
    <util:properties id="applicationProperties" location="classpath:helloWorld.properties" />
    Thanks for your help in advance.
    Last edited by scorpi77; Apr 30th, 2010, 04:35 AM. Reason: removed quotes from util:properties tag

  • #2
    have multiple files configured with different ids in the same tag <utilroperties> . this works well for multiple files too. You can get the value in the second file using the id that u use for that property file.

    Priya

    My blog: spring/hibernate tips

    Comment


    • #3
      Hi Priya,

      Thanks for your answer but this will not solve the problem I am facing.

      Let me try to be bit more clear in what I am looking to achieve.

      I have the following piece of code working perfectly fine:

      Code:
      <bean id="applicationProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
      		<property name="locations">
      			<list>
      				<value>classpath:helloWorld.properties</value>
      	<value>classpath:helloWorld-${environmentName}.properties</value>
      </list>
      		</property>
      		<property name="ignoreResourceNotFound" value="true" />
      		<property name="ignoreUnresolvablePlaceholders" value="true" />
      </bean>
      The above code loads all the property names and values from helloWorld.properties file then from helloWorld-int.properties file given that my environmentName is set to int

      helloWorld.properties file has a property mediaPath set to /tmp/media/ and helloWorld-int.properties file also has a property mediaPath set to /nfs/content/media/.

      Now at runtime @Value("#{applicationProperties.mediaPath}") will return /tmp/media/ by default.

      When running in INT environment where environmentName is set to int at runtime @Value("#{applicationProperties.mediaPath}") will return /nfs/content/media/.

      I would like to achieve the above using <utilroperties/> tag.

      Something along these lines which is not allowed in Spring 3.0:

      <utilroperties id="applicationProperties" local-override="true">
      <property name="locations">
      <list>
      <value>classpath:helloWorld.properties</value>
      <value>classpath:helloWorld-${environmentName}.properties</value>
      </list>
      </property>
      </utilroperties>

      I hope this helps.

      Thanks

      Comment


      • #4
        Did you ever figure this out? I'm trying to do the same thing!

        Comment


        • #5
          I managed to load property values in my Java class using @Value annotation:

          Code:
           
          @Value("${environment.url}")
          private String environmentUrl;
          This will set "environment.url" property value to environmentUrl at runtime.

          In my spring config file I am still using the good old PropertyPlaceholderConfigurer instead of Spring 3.x <utilroperties .../>

          Entry in my Spring configuration file:

          HTML Code:
          <bean id="applicationProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
          		<property name="locations">
          			<list>
          				<value>classpath:helloWorld.properties</value>
          	<value>classpath:helloWorld-${environmentName}.properties</value>				
          			</list>
          		</property>
          		<property name="ignoreResourceNotFound" value="true" />
          		<property name="ignoreUnresolvablePlaceholders" value="true" />
          	</bean>

          The above enabled me to use property values in my Java class. I will do some further investigation into how to use <utilroperties .../> to load multiple environment specific property files.

          Comment

          Working...
          X