Host-specific configuration files in Spring, with fallback

I was very happy to find a practical example of how to use host-specific configuration files in Spring, but unfortunately, the given example still forces one to specify a configuration entry for each host that the application might ever be deployed on.  I am lazy, I would like to have a reasonable fallback, and only configure for the specific exception cases.  Hence I have enhanced Jeff's code a little further:

// In class HostPrecedingPropertyPlaceholderConfigurer
protected String resolvePlaceholder(String placeholder, Properties props) {
try {
if (placeholder.startsWith("HOST.")) {
String hostname = InetAddress.getLocalHost().getHostName();
String hostSpecific = placeholder.replaceFirst("HOST", hostname);
log.debug("Looking for property " + hostSpecific);
String value = props.getProperty(hostSpecific);
if (value == null) {
log.debug("Falling back to default property " + placeholder);
value = props.getProperty(placeholder);
}
return value;
} else {
return props.getProperty(placeholder);
}
} catch (UnknownHostException e) {
log.warn(e);
return null;
}
}

Now, my ${HOST.jdbc.url} in the Spring context file will first look for my hostname.jdbc.url property, but alas, if that returns null, it will default to the value of the HOST.jdbc.url property, enabling me to have a properties file like this:

prodweb.jdbc.url=jdbc:mysql://proddata/db
testweb.jdbc.url=jdbc:mysql://testdata/db
mstest.jdbc.url=jdbc:sqlserver://mstest\\sql2005;database=db;integratedSecurity=true
HOST.jdbc.url=jdbc:mysql://localhost/db

It might be even nicer if it looked for default.jdbc.url, or fallback.jdbc.url, depending on your taste. :-)

Trip tracker

Added Tomek & Rita's trip tracker to the left sidebar.

Apparently it cannot just be copy-pasted into Edit HTML section as-is... :-(
But it can be done via the Layouts / Page Elements section!  Here is how:
After clicking Add a Page Element, a new window will appear.  In the new window, choose:
Well, the layout of these instructions is now all messy... I don't really know how to arrange pictures in a blogger post yet.  But hey!  after you add the new HTML/JavaScript element, it will ask you for the title (anything) and for the actual code (which you have from whereever you got it).  Save, and then you can already arrange your new widget by drag-and-dropping it to the right location:


There you should have it!
:-)

First Post!

:-)