Results 1 to 5 of 5

Thread: multiple property files for PropertyPlaceholderConfigurer

  1. #1
    Join Date
    Oct 2006
    Posts
    156

    Default multiple property files for PropertyPlaceholderConfigurer

    Hi,

    I have the following bean in my Spring configuration file

    Code:
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">						
    	<property name="location">
    		
    		<!-- Remove one of these depending on whether running on windows / unix -->
    		
    		<value>file:/usr/local/tomcat/liferay/WEB-INF/jdbc.properties</value>
    		<value>file:///C|/workspace/ext-web/docroot/WEB-INF/jdbc.properties</value>
    	</property>
    </bean>

    I need to remove one of the <value> elements depending on whether I'm running on Unix or Windows, which is annoying. Is these any way that I can provide a list of file paths, and Spring will just use the first valid one that it finds?

    By the way, I'm using Spring 1.2.

    Thanks in advance,
    DM

  2. #2
    Join Date
    Jul 2006
    Location
    Philadelphia, PA, USA
    Posts
    341

    Default

    Hey domurtag,

    Take a look at this post for an example of using an environment variable to determine the actual location.
    Arthur Loder
    Software Engineer
    Fancast
    Comcast Interactive Media

  3. #3
    Join Date
    Aug 2006
    Location
    Now Germany, previously Ukraine
    Posts
    1,546

    Default

    Quote Originally Posted by Arthur Loder View Post
    Hey domurtag,

    Take a look at this post for an example of using an environment variable to determine the actual location.
    Would not work with JDK 1.4 (does no support environment variables).
    Do not know which JDK original posters uses.

  4. #4
    Join Date
    Jul 2006
    Location
    Philadelphia, PA, USA
    Posts
    341

    Default

    Can you use multiple PropertyPlaceholderConfigurers, one with a lower order/higher precedence that determines the location of the actual properties file? I think I tried something like that once; seems like it might work.

    Code:
    <bean id="propertyConfigurerZero" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
       <property name="location">
          <value>actualPropLocation.properties</value>
       </property>
       <property name="order" value="0" />
       <!-- below is needed because this is not the last configurer -->
       <property name="ignoreUnresolvablePlaceholders" value="true"/>
    </bean>
    
    <bean id="propertyConfigurerOne" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
       <property name="location">
          <value>${actualPropLocation}</value>
       </property>
       <property name="order" value="1" />
    </bean>
    actualPropLocation.properties:
    Code:
    #actualPropLocation=file:/usr/local/tomcat/liferay/WEB-INF/jdbc.properties
    actualPropLocation=file:///C|/workspace/ext-web/docroot/WEB-INF/jdbc.properties
    Last edited by Arthur Loder; Dec 8th, 2006 at 08:08 AM. Reason: added ignoreUnresolvablePlaceholders property
    Arthur Loder
    Software Engineer
    Fancast
    Comcast Interactive Media

  5. #5
    Join Date
    Oct 2006
    Posts
    156

    Default

    Thanks for your suggestions, but I don't think any of these solutions give me what I want, i.e. a configuration that will work on Windows/Unix without any changes.

    Currently I need to change the <value> element.
    With the env. var. suggestion, I'd need to change an env. var.
    With Arthur's suggestion I'd need to change a property in actualPropLocation.properties.

    All of these options seem pretty much equivalent to me, but thanks for the help all the same.

Posting Permissions

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