问题
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