gpt4 book ai didi

config - 包含 ${HOME}/.app/someconfig.conf 中的配置

转载 作者:行者123 更新时间:2023-12-02 06:39:48 25 4
gpt4 key购买 nike

我需要将一些属性文件包含到我的类型安全配置中,例如

include ${user.HOME}"/.app/db-test.conf"

但是解析器提示:

com.typesafe.config.ConfigException$Parse: dev/application.conf: 47: include keyword is not followed by a quoted string, but by: '${'user.HOME'}'
com.typesafe.config.ConfigException$Parse: dev/application.conf: 47: include keyword is not followed by a quoted string, but by: '${'user.HOME'}'
at com.typesafe.config.impl.Parser$ParseContext.parseError(Parser.java:329)
at com.typesafe.config.impl.Parser$ParseContext.parseError(Parser.java:325)
at com.typesafe.config.impl.Parser$ParseContext.parseInclude(Parser.java:574)
at com.typesafe.config.impl.Parser$ParseContext.parseObject(Parser.java:624)
at com.typesafe.config.impl.Parser$ParseContext.parseValue(Parser.java:408)
at com.typesafe.config.impl.Parser$ParseContext.parseObject(Parser.java:657)
at com.typesafe.config.impl.Parser$ParseContext.parse(Parser.java:832)
at com.typesafe.config.impl.Parser.parse(Parser.java:34)

如何在 include 语句中使用系统属性/环境变量?

最佳答案

您可以在加载配置的代码中手动执行此操作吗?

Config baseConfig = ConfigFactory.load();
// Probably want error checking here.
Config testConfig = ConfigFactory.parseFile(
new File(System.getenv("HOME") + "/.app/db-test.conf"));
// You may need to change your resolution order, depending on what you're doing in your
// default config.
testConfig.resolve();
Config finalConfig = baseConfig.withFallback(testConfig);

关于config - 包含 ${HOME}/.app/someconfig.conf 中的配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19074239/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com