Configuration Lifecycle.

There are some stages during the Configuration process which may be interesting for the developer. You can actually interact with the ConfigurationManager or at least get notified about things done. To use this functionality you just have to annotate the method accordingly as showed in the next example:
public class Configurable {
	@Configure private String somevalue;
	 * Usually you don't need to store the environment, its made here, to make the debug messages more verbose.
	private Environment environment;
	public Configurable(Environment anEnvironment){
		environment = anEnvironment;
	public String toString(){
		return "!!! Configurable "+environment+" somevalue: "+somevalue;
	public void setSomevalue(String aValue){
		somevalue = aValue;
		System.out.println(this+": my property somevalue has been set to: "+somevalue);
	@BeforeConfiguration public void callBeforeEachConfiguration(){
		System.out.println(this+" will be configured now");
	@BeforeInitialConfiguration public void callBeforeInitialConfigurationOnly(){
		System.out.println(this+" will be INITIALY configured now");
	@BeforeReConfiguration public void callBeforeReConfigurationOnly(){
		System.out.println(this+" will be RE-configured now");

	@AfterConfiguration public void callAfterEachConfiguration(){
		System.out.println(this+" has been configured");
	@AfterInitialConfiguration public void callAfterInitialConfigurationOnly(){
		System.out.println(this+" has been INITIALY-configured");
	@AfterReConfiguration public void callAfterReConfigurationOnly(){
		System.out.println(this+" has been RE-configured");

There are three possible annotations at the begin, three at the end and one at the alternative end of the configuration process.

At the beginning of the configuration process a list of methods is extracted from the class of the configured object.
After that following annotations are being called:


Prior to setting any fields to any values all methods marked BeforeInitialConfiguration or BeforeReConfiguration are called. If this was the initial (first) configuration (usually resulting from a direct call to ConfigurationManager.configure()) all methods annotated BeforeInitialConfiguration are called. Otherwise, if this is a reconfiguration (triggered by a change in the configuration file) all methods annotated BeforeReConfiguration. After that all methods annotated with BeforeConfiguration are called.

During the Configuration.

If anything unrecoverable happens during the annotation (property not parseable in desired type etc) the configuration will be aborted and the configurable left in an undefined state. The ConfigurationManager will throw an Exception to allow the client to handle it accordingly, but prior to that it will call all AbortedConfiguration annotated methods.

After the configuration.

After the configuration process is finished (all fields set, setable methods called) methods annotated AfterConfiguration, AfterInitialConfiguration and AfterReConfiguration are called. First AfterConfiguration methods are called. Than AfterInitialConfiguration / AfterReConfiguration methods are called (reversed order compared to Before configuration)

Call order.

Multiple methods which are annotated by the same annotation are called in order they are in the class body. However, this isn't ensured by ConfigurationManager, it's just the order Class.getMethods() returns. If this will ever be changed in the VM implementation, ConfigureMe's behavior will also change.

  • No labels