Friday, December 13, 2013

Retrieving external config properties from JNDI, environment shell, and/or system properties.

I need to deploy multiple instances of the same WAR in a single Tomcat instance. I've been reading external config properties from System properties (e.g. System.getProperty('ext.xyz')). That won't work when deploying multiple WAR instances. So I whipped this up to read from JNDI as well as System properties (and I threw in reading from environment vars as well).

Then in Config.groovy, I use it thus...

This way my config file doesn't care where the external property comes from. In dev, I can define it as a system property. In prod, I can define it as a JNDI env var.
For completeness, here's how I'm defining the context xml in Tomcat.