1
介紹如何在Play Framework的`conf/application.conf`中查找變量?
根據this documentation應該可以來查找conf/application.conf
中的環境變量。
使用環境變量
您也可以從你的 application.conf文件中引用的環境變量:{?MY_KEY_ENV}
my.key = defaultvalue my.key = ${?MY_KEY_ENV}
這裏,覆蓋領域my.key = $如果 對MY_KEY_ENV沒有任何價值,則會消失,但如果您設置了環境 變量MY_KEY_ENV,則會使用該值。
因爲您可以引用其他變量中的變量,因此請確保您不要將環境變量命名爲與 字段名稱相同。
例如:
MY_TOKEN = foo MY_TOKEN = ${?MY_TOKEN} # Will reference the previous line, NOT your environmentally set variable
嘗試
搬運工-compose.test.yml
sut:
depends_on:
- db
...
environment:
VAR_A: db:3306
CONF/application.conf
db.default.url="jdbc:mysql://${?VAR_A}/app"
問題
出於某種原因,無法查找變量:${: Name or service not known
sut_1 | [info] application - Creating Pool for datasource 'default'
sut_1 | [info] application - Creating Pool for datasource 'default'
sut_1 | [info] - should send 404 on a bad request *** FAILED ***
sut_1 | [info] play.api.Configuration$$anon$1: Configuration error[Cannot connect to database [default]]
sut_1 | [info] at play.api.Configuration$.configError(Configuration.scala:154)
sut_1 | [info] at play.api.Configuration.reportError(Configuration.scala:806)
sut_1 | [info] at
...
sut_1 | [info] Cause: java.net.UnknownHostException: ${: Name or service not known
sut_1 | [info] at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
sut_1 | [info] at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928)
sut_1 | [info] at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)
sut_1 | [info] at java.net.InetAddress.getAllByName0(InetAddress.java:1276)
sut_1 | [info] at java.net.InetAddress.getAllByName(InetAddress.java:1192)
sut_1 | [info] at java.net.InetAddress.getAllByName(InetAddress.java:1126)
sut_1 | [info] at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:190)
sut_1 | [info] at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:297)
sut_1 | [info] at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2232)
sut_1 | [info] at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2265)
sut_1 | [info] ...
問題
如何查找變量在該conf/application.conf
Play框架?