Announcement Announcement Module
Collapse
No announcement yet.
Howto reference a System property in a property file ? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Howto reference a System property in a property file ?

    Hi,
    I have a property file, referenced by a PropertyPlaceholderConfigurer.
    At runtime (prod environment), a directory property (called "solutions.outputDirectory") references a directory on disk
    My properties file is hosted in maven src\main\resources\service.properties :
    Code:
    [...]
    solutions.outputDirectory=/path/to/a/certain/directory
    [...]
    In test environment, i have a copy of this property file, with alternate values :
    hosted in maven src\test\resources\service.properties.

    ==> I would like the same property ("solutions.outputDirectory") to reference the TMP directory.
    Something like :
    Code:
    [...]
    solutions.outputDirectory=sys:java.io.tmpdir
    [...]
    How can i force a property to reference a System property that PropertyPlaceholderConfigurer could interpret (via SPEL ?) dynamically ? Is there a way to do this ?

    Thanks in advance
    ;-)

  • #2
    (found response by myself)

    Response is :
    Code:
    [...]
    solutions.outputDirectory=${java.io.tmpdir}
    [...]
    BUT, if any placeholderPrefix has been defined on PropertyPlaceholderConfigurer :
    e.g
    Code:
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    	<property name="placeholderPrefix" value="service{" />
    	<property name="placeholderSuffix" value="}" />
    	<property name="locations">
    		<list>
    			<value>classpath:properties/service.properties</value>
    		</list>
    	</property>
    </bean>
    ... it MUST be :
    Code:
    [...]
    solutions.outputDirectory=service{java.io.tmpdir}
    [...]
    :-)

    Comment

    Working...
    X