Results 1 to 2 of 2

Thread: property substitution with default doesn't work?

  1. #1
    Join Date
    Sep 2012
    Posts
    5

    Default property substitution with default doesn't work?

    So in the /etc/env-properties file, i have:

    port=1234

    And the substitution in the "testit" bean works fine. Ie, i end up with 1234 in my "testit" bean.

    <!-- use placeholders where we might want a JVM argument -->
    <bean id="propertyPlaceholder"
    class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer"
    p:ignoreResourceNotFound="true"
    p:systemPropertiesModeName="SYSTEM_PROPERTIES_MODE _OVERRIDE" >
    <property name="locations">
    <list>
    <value>file:/etc/env-overrides.properties</value>
    </list>
    </property>
    </bean>

    <bean id="testit" class="java.lang.String">
    <constructor-arg index="0" value="${port}" />
    </bean>

    However, if i change the bean def to use a default value:

    <bean id="testit" class="java.lang.String">
    <constructor-arg index="0" value="${port:666}" />
    </bean>

    I end up with port set to 666, instead of 1234. Of course, the intent is to use 666 if nothing is found in the property file. But i do have "port" defined in the property file, but i end up with the default of 666.

    How is this defaulting supposed to work?
    Last edited by tunkul; Oct 31st, 2012 at 03:32 PM.

  2. #2
    Join Date
    Oct 2012
    Location
    Shenzhen, China
    Posts
    13

    Default

    I tested with <context: property-placeholder> and annotation style injection in Spring 3, the default works just fine.

Posting Permissions

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