Can I have multiple configuration files in DropWizard?

前端 未结 3 1556
独厮守ぢ
独厮守ぢ 2021-02-02 14:28

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

3条回答
  •  梦如初夏
    2021-02-02 15:24

    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);
        }
    }
    

提交回复
热议问题