Dropwizard:必须配置.yml吗? [英] Dropwizard: Is a .yml config mandatory?

查看:262
本文介绍了Dropwizard:必须配置.yml吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基本的 Dropwizard v1.2.0 应用程序。我可以通过运行以下命令从命令行执行它:

I've got a basic Dropwizard v1.2.0 application. I can execute it from my command line by running:

java -jar application.jar server config.yml

Dropwizard是否可以在不传递 config.yml 文件?

Is it possible for Dropwizard to work without passing it a config.yml file?

我之所以问是因为,我的 config.yml 看起来像这样:

I'm asking because, right now, my config.yml looks like this:

mySetting: ${DW_MY_SETTING}
defaultSetting: ${DW_DEFAULT_SETTING:-default value}

我正在使用'DW_MY_SETTING'' DW_DEFAULT_SETTING'环境变量以填充 config.yml ,然后使用config.yml中的值设置 MyConfiguration .java (这是扩展io.dropwizard.Configuration的类的名称)。

I'm using the 'DW_MY_SETTING' and 'DW_DEFAULT_SETTING' environment variables to populate config.yml, and then the values in config.yml are being used to set MyConfiguration.java (that's the name of my class that extends io.dropwizard.Configuration).

我可以只设置直接从环境变量中获取MyConfiguration.java ,而不必麻烦通过 config.yml 文件吗?

Can I just set MyConfiguration.java directly from the environment variables and not bother going through a config.yml file?

预先感谢您

推荐答案

如果要使用 io.dropwizard.Configuration 不指定YAML文件,那么您需要建议它忽略这样的JSON属性:

If you're going to utilize io.dropwizard.Configuration without specifying a YAML file then you need to advise it to ignore JSON properties like this:

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.dropwizard.Configuration;

@JsonIgnoreProperties(ignoreUnknown = true)
public final class EnvironmentOnlyConfig extends Configuration {
    public static String getDwMySetting() {
        return System.getenv("DW_MY_SETTING");
    }
}

这篇关于Dropwizard:必须配置.yml吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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