Can I have multiple configuration files in DropWizard?

Victor Ronin picture Victor Ronin · Feb 25, 2015 · Viewed 12.4k times · Source

I want to have several yaml files for DropWizard. One of them contain sensitive info and one non sensitive.

Can you point me to any docs or example how to have multiple configurations in DropWizard?

Answer

Natan picture Natan · Mar 15, 2015

ConfigurationSourceProvider is your answer.

bootstrap.setConfigurationSourceProvider(new MyMultipleConfigurationSourceProvider());

The following is how dropwizard does it by default. You can easily change it to your own liking.

public class FileConfigurationSourceProvider implements ConfigurationSourceProvider {
    @Override
    public InputStream open(String path) throws IOException {
        final File file = new File(path);
        if (!file.exists()) {
            throw new FileNotFoundException("File " + file + " not found");
        }

        return new FileInputStream(file);
    }
}