您如何覆盖Typesafe Config设置?

问题描述 投票:2回答:2

在我的application.conf文件中,我有类似的东西

platform3.operational.state = "development"

我通过以下方式运行服务

sbt "project p3-s-sink" "run -Dplatform3.operational.state=test"

但是配置属性仍然是“ development”

如何覆盖类型安全配置设置?

sbt typesafe typesafe-config
2个回答
2
投票

也许此博客可以帮助您:

很遗憾,sbt run不支持Java系统属性,因此在运行sbt时您无法使用命令行来调整设置。 sbt-revolver插件允许您在派生的JVM中运行应用程序,但确实允许您使用命令行传递Java参数。

http://blog.michaelhamrah.com/2014/02/leveraging-typesafes-config-library-across-environments/


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>

请注意中间段落:“加载将包括已覆盖的系统属性,defaultReference和defaultOverrides也将包含在内。

直接执行时可以按预期工作吗?

© www.soinside.com 2019 - 2024. All rights reserved.