我可以在DropWizard中拥有多个配置文件吗? [英] Can I have multiple configuration files in DropWizard?

查看:152
本文介绍了我可以在DropWizard中拥有多个配置文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为DropWizard提供几个yaml文件。其中一个包含敏感信息,一个包含非敏感信息。

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

您能指点我在DropWizard中如何获得多个配置的任何文档或示例吗?

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

推荐答案

ConfigurationSourceProvider 是您的答案。

bootstrap.setConfigurationSourceProvider(new MyMultipleConfigurationSourceProvider());

以下是 dropwizard默认执行。您可以根据自己的喜好轻松更改它。

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

这篇关于我可以在DropWizard中拥有多个配置文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆