Dropwizard: Is a .yml config mandatory?

非 Y 不嫁゛ 提交于 2019-12-10 17:07:31

问题


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

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

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

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

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).

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

Thanks in advance for your help.


回答1:


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


来源:https://stackoverflow.com/questions/46682279/dropwizard-is-a-yml-config-mandatory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!