Friday, May 07, 2010

PropertyPlaceholderConfigurer in Spring 2.5

While not explicitly highlighted in the Spring 2.5 “What’s New” section, this is a nice little bit to remove a few lines of XML. Spring 2.5 (with the introduction of a new “context:” namespace) takes the common use of a PropertyPlaceholderConfigurer externalizing properties and folds it from the awkward 5-line syntax into a single line.

Before (Spring 2.0 and earlier):
<bean id="propertyConfigurer"
 <property name="location">

After (Spring 2.5):
<context:property-placeholder location="file:${user.home}/"/>

The nit-picky will note that you will need to add in the spring-context-2.5.xsd schema reference, however you may be using that already anyway in Spring 2.5 to take advantage of some of the Java-based annotation functionality.

No comments: