我想让我的Play应用程式使用不同的资料库进行测试,本地和制作(生产环境为Heroku)环境。
在 .conf 我有:
db.default.driver = org.postgresql.Driver %dev.db.default.url =jdbc:postgresql:// localhost / foobar%test.db.default.url =jdbc:postgresql:// localhost / foobar-test %prod.db.default.url = $ {DATABASE_URL}t似乎工作。当我运行玩测试或玩跑,所有DB访问失败, b $ b
配置错误[缺少配置[db.default.url]](Configuration.scala:258)我有几个问题:
-
一般来说,我对于如何配置数据库在Play中有点困惑:它看起来像有简单的 db , db。 [DBNAME] 和 db。 [DBNAME] .url ,不同的教程在中做出不同的选择。某些看起来像他们应该工作的表达式(例如 db.default.url =jdbc:...失败,并显示一个错误, )。
-
我看过其他人建议我分别创建 prod.conf , dev.conf 和 test.conf 文件,每个文件包含 application.conf 然后包含DB特定的配置。但在这种情况下,当我从播放控制台运行 test 时,如何指定要使用的数据库?
-
%env 语法应该在Play 2中使用吗?
-
为玩测试指定环境的正确方法是什么?
在Play 2中没有不同的配置环境。而是您只需在 conf / application.conf 文件中设置或覆盖配置参数。一种方法是在 play 命令行,例如:
play -Ddb.default.driver = org.postgresql.Driver -Ddb.default.url = $ DATABASE_URL〜run您还可以告诉Play使用不同的配置文件:
播放-Dconfig.file = conf / prod。 conf〜run有关Heroku的Procfile示例,请参阅: github/jamesward/play2bars/blob/scala-anorm/Procfile a>
Play文件中的更多详细信息: www.playframework/documentation/2.0/配置
I'd like my Play app to use different databases for test, local and production (production is Heroku) environments.
In application.conf I have:
db.default.driver=org.postgresql.Driver %dev.db.default.url="jdbc:postgresql://localhost/foobar" %test.db.default.url="jdbc:postgresql://localhost/foobar-test" %prod.db.default.url=${DATABASE_URL}This doesn't seem to work. When I run play test or play run, all DB access fails with:
Configuration error [Missing configuration [db.default.url]] (Configuration.scala:258)I have a few questions about this:
In general, I'm a little confused about how databases are configured in Play: it looks like there's plain db, db.[DBNAME] and db. [DBNAME].url and different tutorials make different choices among those. Certain expressions that seem like they should work (e.g. db.default.url = "jdbc:..." fail with an error that a string was provided where an object was expected).
I've seen other people suggest that I create separate prod.conf, dev.conf and test.conf files that each include application.conf and then contain DB-specific configuration. But in that case, how do I specify what database to use when I run test from the Play console?
Is the %env syntax supposed to work in Play 2?
What's the correct way to specify an environment for play test to use?
In Play 2 there aren't different config environments. Instead you just set or override the config parameters in the conf/application.conf file. One way to do it is on the play command line, like:
play -Ddb.default.driver=org.postgresql.Driver -Ddb.default.url=$DATABASE_URL ~runYou can also tell Play to use a different config file:
play -Dconfig.file=conf/prod.conf ~runFor an example Procfile for Heroku, see: github/jamesward/play2bars/blob/scala-anorm/Procfile
More details in the Play Docs: www.playframework/documentation/2.0/Configuration
更多推荐
如何在Play 2.0中为每个环境设置不同的数据库?
发布评论