gpt4 book ai didi

java - ConfigFactory ParseFile 通过 Java 系统属性的变量替换进行解析

转载 作者:行者123 更新时间:2023-11-30 02:29:13 29 4
gpt4 key购买 nike

我在尝试使用 typesafehub ConfigFactory fileParser 的变量替换时遇到问题

我的代码是

Configuration(ConfigFactory.parseFile(new File("/Users/TDong/files/app.conf")).resolve())

我的 app.conf 文件包含

path = ${java.home}

在每次解析时,我都无法通过变量替换来解析该变量以找到 java 系统属性 home。任何想法如何使这项工作

最佳答案

要利用最重要的功能,您需要坚持使用 ConfigFactory.load() 或自行处理 merging configuration通过 Config#withFallback 方法。其实是这样的ConfigFactory#load() 有效。

https://github.com/typesafehub/config#standard-behavior

The convenience method ConfigFactory.load() loads the following (first-listed are higher priority):

  • system properties application.conf (all resources on classpath with this name)
  • application.json (all resources on classpath with this name)
  • application.properties (all resources on classpath with this name)
  • reference.conf (all resources on classpath with this name)

恕我直言,您应该依赖默认行为并使用 -Dconfig.file=/path/to/your.conf 将文件作为参数传递给您的应用程序。

我强烈建议您阅读写得非常好的文档。

关于java - ConfigFactory ParseFile 通过 Java 系统属性的变量替换进行解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44686518/

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