Announcement Announcement Module
Collapse
No announcement yet.
Question about property-placeholder/PropertyPlaceholderConfigurer Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Question about property-placeholder/PropertyPlaceholderConfigurer

    Is there anyway to configure the placeholder for an optional property?

    For example
    <contextroperty-placeholder location="classpath:order.properties"/>
    <bean id="orderProperty" class="com.foo.MyOrderProperty">
    <property name="orderEnabled" value="${OrderEnabled}"/>
    <property name="orderUrl" value="${orderUrl}"/>
    </bean>

    Our order.properties doesn't have property orderEnabled, it is on purpose, since orderEnabled always needs to be true by default. Only for very rare cases, we might need to set it to false.

    However, PropertyPlaceholderConfigurer would throw exception due to the missing property.
    Invalid bean definition with name 'orderProperty' defined in class path resource [applicationContext-service.xml]: Could not resolve placeholder 'OrderEnabled'

    I tried add an attribute ignore-unresolvable="true" for property-placeholder. But that did not help either.
    <contextroperty-placeholder location="classpath:order.properties" ignore-unresolvable="true"/>

    Any suggestions on how to handle this case?

    Thanks

  • #2
    Please use [ code][/code ] tags when posting code/xml/stacktraces that way it remains readable.

    If you ignore the placeholder spring will try to set the value to "${OrderEnabled}" because that is what it is then configured to. Which obviously isn't a valid boolean value... You probably want to take a look at the PropertyOverrideConfigurer (next to that if I'm not mistaken in Spring 3 you can specify defaults for the placeholder also),

    Comment

    Working...
    X