

Some components or resources may need to be configured before being used in our applications. While so far we used Application's init method to initialize these kinds of entities, Wicket offers a more flexible and modular way to configure our classes. 

During application's bootstrap Wicket searches for any properties file named wicket.properties  placed in one of the classpath roots visible to the application. When one of these files is found, the initializer defined inside it will be executed. An initializer is an implementation of interface @org.apache.wicket.IInitializer@ and is defined inside wicket.properties with a line like this:

{code}
initializer=org.wicketTutorial.MyInitializer
{code}

The fully qualified class name corresponds to the initializer that must be executed. Interface @IInitializer@ defines method init(Application) which should contain our initialization code, and method @destroy(Application)@ which is invoked when application is terminated:

{code}
public class MyInitializer implements IInitializer{

	public void init(Application application) {
		//initialization code 
	}

	public void destroy(Application application) {
		//code to execute when application is terminated
	}	
}
{code}

Only one initializer can be defined in a single wicket.properties file. To overcome this limit we can create a main initializer that in turn executes every initializer we need:

{code}
public class MainInitializer implements IInitializer{

	public void init(Application application) {
		new AnotherInitializer().init(application);
		new YetAnotherInitializer().init(application);
		//... 
	}
	//destroy... 
}
{code}