18. July 2009
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:
I came up with the following basic requirements:
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";
}