在我的application.conf文件中,我有类似
的内容platform3.operational.state = "development"
我用
运行我的服务sbt "project p3-s-sink" "run -Dplatform3.operational.state=test"
但配置属性仍然是“开发”
如何覆盖typesafe-config设置?
答案 0 :(得分:1)
来自ConfigFactory.systemProperties()的JavaDoc [ConfigFactory.java]:
* Gets a <code>Config</code> containing the system properties from * {@link java.lang.System#getProperties()}, parsed and converted as with * {@link #parseProperties}. * <p> * This method can return a global immutable singleton, so it's preferred * over parsing system properties yourself. * <p> * {@link #load} will include the system properties as overrides already, as * will {@link #defaultReference} and {@link #defaultOverrides}. * * <p> * Because this returns a singleton, it will not notice changes to system * properties made after the first time this method is called. Use * {@link #invalidateCaches()} to force the singleton to reload if you * modify system properties. * * @return system properties parsed into a <code>Config</code>
注意中段:&#34; load将系统属性包含为override,defaultReference和defaultOverrides&#34;。
直接执行时它是否按预期工作?
答案 1 :(得分:1)
也许这个博客可以帮助你:
不幸的是,sbt run不支持java系统属性,因此在运行sbt时无法使用命令行调整设置。 sbt-revolver插件允许您在分叉的JVM中运行应用程序,它允许您使用命令行传递java参数。
http://blog.michaelhamrah.com/2014/02/leveraging-typesafes-config-library-across-environments/