Spring is great for creating flexible applications by assembling loosely coupled components using XML. Here’s a simple Spring configuration file:
<bean id="hello" class="example.HelloWorldBean" />
Except that now you have to go back to your context assisted IDE and write some Java to launch it!
Here’s my previous password passed to Spring example run from Oddjob:
Run as a GUI, Oddjob provides a simple form for entering properties including a password prompt.
I previously presented a
CustomPropertyConfgurer that allows properties outside of Spring to be accessed from within Spring. The article was syndicated by DZone where a reader noted that in fact the Spring class
PropertySourcesPlaceholderConfigurer has a
setProperties method, and so for my particular example, the
CustomPropertyConfigurer was redundant.
(Please note there as a postscript to this post: A Simpler Custom Property in Spring)
<context:property-placeholder> is a really easy way to provide property replacements in Spring configurations with values from a standard Java Properties file. But what if you don’t want a property hard coded into a file – a clear text password for instance? Spring provides all the bits and pieces to write your own property replacement. Let me introduce my