1

I have read the documentation concerning falling back to environment variables at https://github.com/typesafehub/config/blob/master/HOCON.md#substitution-fallback-to-environment-variables. My understanding was that it would pickup any envars. So for instance, if from the shell I was able to do echo $HOSTNAME and see a non-empty response then HOCON should do that as well.

In my application.conf I have a line

akka.remote.netty.tcp.hostname = ${HOSTNAME}

However, my app is not happy with this and fails to start with.

/conf/application.conf: 9: Could not resolve substitution to a value:  ${HOSTNAME}

Is this a user issue? A shell issue? I am able to login as the user and echo $HOSTNAME

Tagging this scala and akka since that userbase probably has the most exposure to HOCON

4

3 回答 3

2

HOCON 没有选择 envar 的原因是我的应用程序作为 linux 服务(Centos 6.5)运行,它清除了大多数环境变量。

有关问题的相关描述,请参阅https://unix.stackexchange.com/questions/44370/how-to-make-unix-service-see-environment-variables

于 2015-04-16T17:47:25.067 回答
1

这是在黑暗中拍摄的,但是您使用的是旧版本的 typesafe-config 吗?也许它是一个较新的功能?正如您所描述的那样,该功能似乎已被宣传,但是如果您将 typesafe-config 作为临时依赖项(例如来自 akka)引入,那么您可能会获得旧版本。

如果删除 .conf 文件中的替换(因此解析成功)然后打印出 ConfigFactory.systemEnvironment() 的内容会发生什么?供参考:http ://typesafehub.github.io/config/latest/api/com/typesafe/config/ConfigFactory.html#systemEnvironment--

于 2015-04-15T21:33:02.173 回答
1

HOSTNAME 不是环境变量。这是一个 bash 内部变量。有关更多详细信息,请参阅https://superuser.com/questions/132489/hostname-environment-variable-on-linux

于 2016-02-11T04:41:53.427 回答