I have been on a number of Java projects recently and one of the things I end up brewing for each of these projects is some enhanced management of runtime properties.

Having said there are problems with using .properties files they are well understood and supported by all the major Java tools and IDEs. There would have to be a very strong reason to use another format (and no I don’t mean XML).

The basic problem is that the Java API supports property loading but no semantic validation of the supplied property values. In addition it is quite common to want to vary the properties from one environment to another (otherwise the need for properties would not exist). When trying to diagnose a problem is it very useful to know where the value of a property came from. In fact to start with I would like to know that the value of the runtime properties is in the first place.

During the course of the last couple of Java web projects I have come up with the following:

  • The runtime properties are available through a simple web page - typically secured behind a masked internal URL.</li>
  • Sensitive property values such as password are obscured.</li>
  • Along with the property name and value some notion (typically a filename) of where the property value came from.</li>
  • An assessment of the property value.</li>

Requirements

I came up with the following basic requirements:

  • I want to declare the property requirements within the application source.</li>
  • I want to be able to specify if the property is required</li>
  • I want to know at runtime where a property came from</li>
  • I want to fail fast if a required property is missing or malformed.</li>
public class TestRuntimePropeties {
    @RuntimeProperty(name = "some.property.name", defaultValue = "foo.bar")
    public String somePropertyName;

	@RuntimeProperty(name = "required.property.name", required = true)
    public String requiredProperty;

	@RuntimeProperty(name = "missing.property.name")
	public String missingProperty = "missing";

    public String nonPropertyField = "noproperty";
}
comments powered by Disqus