Play Framework 2.3对OpenShift数据库令牌替换不起作用

时间:2014-10-12 09:26:45

标签: openshift playframework-2.3

我正在尝试将Play Framework 2.3应用程序部署到OpenShift。

我正在关注此示例:https://github.com/JamesSullivan/play2-openshift-quickstart

构建和部署应用程序正在运行(我的意思是git存储库的push正在运行且构建成功完成),但在启动期间,我在play.log中看到此错误:< / p>

AbstractConnectionHook -
Failed to obtain initial connection Sleeping for 0ms and trying again. 
Attempts left: 0. Exception: null.
Message:No suitable driver found for jdbc:${OPENSHIFT_POSTGRESQL_DB_URL}
Oops, cannot start the server.
Configuration error: Configuration error[Cannot connect to database [default]]
    at play.api.Configuration$.play$api$Configuration$$configError(Configuration.scala:94)
    at play.api.Configuration.reportError(Configuration.scala:743)
    at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:247)
    at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:238)
    at scala.collection.immutable.List.map(List.scala:272)
    at play.api.db.BoneCPPlugin.onStart(DB.scala:238)
    at play.api.Play$$anonfun$start$1$$anonfun$apply$mcV$sp$1.apply(Play.scala:91)
    at play.api.Play$$anonfun$start$1$$anonfun$apply$mcV$sp$1.apply(Play.scala:91)
    at scala.collection.immutable.List.foreach(List.scala:381)
    at play.api.Play$$anonfun$start$1.apply$mcV$sp(Play.scala:91)
    at play.api.Play$$anonfun$start$1.apply(Play.scala:91)
    at play.api.Play$$anonfun$start$1.apply(Play.scala:91)
    at play.utils.Threads$.withContextClassLoader(Threads.scala:21)
    at play.api.Play$.start(Play.scala:90)
    at play.core.StaticApplication.<init>(ApplicationProvider.scala:55)
    at play.core.server.NettyServer$.createServer(NettyServer.scala:244)
    at play.core.server.NettyServer$$anonfun$main$3.apply(NettyServer.scala:280)
    at play.core.server.NettyServer$$anonfun$main$3.apply(NettyServer.scala:275)
    at scala.Option.map(Option.scala:145)
    at play.core.server.NettyServer$.main(NettyServer.scala:275)
    at play.core.server.NettyServer.main(NettyServer.scala)
Caused by: java.sql.SQLException: No suitable driver found for jdbc:${OPENSHIFT_POSTGRESQL_DB_URL}
    at java.sql.DriverManager.getConnection(DriverManager.java:596)
    at java.sql.DriverManager.getConnection(DriverManager.java:215)
    at com.jolbox.bonecp.BoneCP.obtainRawInternalConnection(BoneCP.java:363)
    at com.jolbox.bonecp.BoneCP.<init>(BoneCP.java:416)
    at com.jolbox.bonecp.BoneCPDataSource.getConnection(BoneCPDataSource.java:120)
    at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:240)
    ... 18 more

所以看起来$ {OPENSHIFT_POSTGRESQL_DB_URL}环境变量令牌替换不起作用。

如果我登录我的应用程序,我会通过env看到这一点(显然我已经替换了用户名,密码,IP和端口以便在此处发布):

OPENSHIFT_POSTGRESQL_DB_URL=postgresql://xxxx:yyyy@ip:port

我也尝试过使用其他环境变量,例如OPENSHIFT_POSTGRESQL_DB_HOST,但这些变量也没有被替换。

openshift.conf的相关部分如下所示:

db.default.driver=org.postgresql.Driver
db.default.url="jdbc:${OPENSHIFT_POSTGRESQL_DB_URL}"
db.default.user=myappuser
db.default.password=myapppassword

在链接的快速入门项目中,以下命令用于启动Play服务器(同样,为了本文的目的,我更换了server-ip):

/app-root/runtime/repo/target/universal/stage/bin/myapp
"-DapplyEvolutions.default=true" 
-Dhttp.port=8080 -Dhttp.address=server-ip 
-Dconfig.resource=openshift.conf

您可以看到被引用的openshift.conf文件。

1 个答案:

答案 0 :(得分:0)

我尝试了很多东西,最终我发现了一些有用的东西:

db.default.driver=org.postgresql.Driver
db.default.url="jdbc:postgresql://"${OPENSHIFT_POSTGRESQL_DB_HOST}":"${OPENSHIFT_POSTGRESQL_DB_PORT}/mydb
db.default.user=(((db-user)))
db.default.password=(((dp-password)))

结果是,您似乎需要非常仔细地注意正确使用引号字符。

由于最后一个引号字符将字符串 before 关闭到OPENSHIFT_POSTGRESQL_DB_PORT变量,因此看起来“错误”(乍一看)。