Changing the Load Order

Changing the Loader Order

It's easy to edit or change the order of the loaders:

import org.yarnandtail.andhow.*;
import org.yarnandtail.andhow.load.std.*;

public class ModifyStdLoaderOrder implements AndHowInit {
    @Override
    public AndHowConfiguration getConfiguration() {
        return AndHow.findConfig()
            .setStandardLoaders(StdEnvVarLoader.class, StdJndiLoader.class);
    }
}

The example class above implements the AndHowInit interface. At startup, AndHow will discover this class and use it to configure itself. In this case, the standard list of seven loaders has been replaced with just two.

Adding custom loaders

Its also possible to leave the standard list intact and insert loaders between the standard loaders:

@Override
public AndHowConfiguration getConfiguration() {
    PropFileOnClasspathLoader pfl = new PropFileOnClasspathLoader();
    pfl.setFilePath("/my.properties");
    return AndHow.findConfig()
        .insertLoaderBefore(StdJndiLoader.class, pfl);
}

Only a single instance of each of the Standard loaders is allowed - these are the loaders with names start with 'Std' and implement the StandardLoader interface, however, it is OK to insert any number of any other loader.

Last updated