Over a million developers have joined DZone.

Using Default Values for Properties in Spring

· Java Zone

Learn more about how the Java language, tools and frameworks have been the foundation of countless enterprise systems, brought to you in partnership with Salesforce.

I was looking through the Spring Greenhouse application and discovered an existing feature that I was unaware of. We can set a default value when configuring PropertyPlaceholderConfigurer.

1. Set the default value separator in config

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:application.properties" />
<property name="ignoreResourceNotFound" value="true" /> <-- Ignore file not found -->
<property name="ignoreUnresolvablePlaceholders" value="true" /> <-- Ignore when tokens are not found -->

<!-- Token that separates default values on a placeholder-by-placeholder basis e.g. ${server.name?localhost} -->
<property name="valueSeparator" value="?" />

2. Set the default values for your properties

<bean id="myServer" class="com.gordondickens.myapp.MyServerConfig">
<property name="serverName" value="${server.name?localhost}" />
<property name="serverPort" value="${server.port?25}" />


  • If unspecified, the default separator is a colon “:”
  • This option is not available when using the “context” namespace – (submitted Jira ticket: SPR-7794)

From http://gordondickens.com/wordpress/2010/12/06/using-default-values-for-properties-in-spring/

Discover how the Force.com Web Services Connector (WSC) is a code-generation tool and runtime library for use with Force.com Web services, brought to you in partnership with Salesforce.


The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}