application.conf 中的 Scala 环境 ${USER} [英] Scala environment ${USER} in application.conf

查看:64
本文介绍了application.conf 中的 Scala 环境 ${USER}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了 2013 年写的名为Play for Scala"的书,并看到了这样的代码示例:

I read the book titled "Play for Scala" written in 2013 and see an code example like this one:

在 application.conf 文件中:

inside application.conf file:

environment.user = ${USER}

在一些模板文件中:

@()(implicit messages: Messages)
@import java.util.Date
@import play.api.Play.current

<footer>
    lang = @messages.lang.code
    user = @current.configuration.getString("environment.user")    // <<--- this line
    date = @(new Date().format("yyyy-MM-dd HH:mm"))
</footer>

运行示例后出现错误:

application.conf @ file:/C:/Users/Maciek/IdeaProjects/play-scala/target/scala-2.11/classes/application.conf: 18: 无法解析替换值:${用户}

请问什么是${USER}环境变量,它是从哪里来的?为什么它不起作用?

I would like to ask what is ${USER} environment variable, where does it come from? and why does it not work?

我知道在书中播放版本是 2.1 而我的是 2.4.2

I know that in the book play version is 2.1 and mine is 2.4.2

推荐答案

这更像是一个操作系统问题.在 Linux/Unix 上,您通常将 $USER 定义为当前用户(正在运行 shell 或您的应用程序).要检查 bash 中的值,请执行以下操作:

It's more of an OS question. On Linux/Unix you usually have $USER defined as the current user (who is running shell or your app). To check the value in bash do:

# echo $USER
yourname

在 Windows 中,您可以通过 cmd 使用:

In Windows you can check it from cmd with:

C:\> echo %USER%
%USER%

正如你所看到的,它没有在我的机器上定义.也许您正在使用 Windows 并遇到相同的错误.您可以在您的操作系统中设置 USER 环境变量,以便它能够在您的 conf 中找到该值或提供后备值.

As you can see it's not defined on my machine. Perhaps you are using Windows and getting the same error. You can set USER environment variable in your OS for it to be able to find the value or provide a fallback value in your conf.

这篇关于application.conf 中的 Scala 环境 ${USER}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆