如何为 Play 2.0 设置 PostgreSQL?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10282402/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-20 23:50:59  来源:igfitidea点击:

How to set up PostgreSQL for Play 2.0?

postgresqlscalaplayframework-2.0

提问by Thomas Kremmel

I'd like to configure PostgreSQL for my Play app, but am getting the following error:

我想为我的 Play 应用程序配置 PostgreSQL,但出现以下错误:

! Internal server error, for request [GET /] ->

java.util.concurrent.TimeoutException: Futures timed out after [300000] milliseconds    at
akka.dispatch.DefaultPromise.ready(Future.scala:834)
~[akka-actor.jar:2.0]   at
akka.dispatch.DefaultPromise.result(Future.scala:838)
~[akka-actor.jar:2.0]   at akka.dispatch.Await$.result(Future.scala:74)
~[akka-actor.jar:2.0]   at
play.core.ReloadableApplication.get(ApplicationProvider.scala:108)
~[play_2.9.1.jar:2.0]   at
play.core.server.Server$class.sendHandler(Server.scala:59)
[play_2.9.1.jar:2.0]    at
play.core.server.Server$$anonfun$getHandlerFor.apply(Server.scala:89)
[play_2.9.1.jar:2.0] [error] application - 

! @6a64i2p5o - Internal server error, for request [GET /] ->

play.api.PlayException: Not initialized [?]     at
play.api.PlayException$.apply(Exceptions.scala:122)
~[play_2.9.1.jar:2.0]   at
play.core.ReloadableApplication.<init>(ApplicationProvider.scala:94)
~[play_2.9.1.jar:2.0]   at
play.core.server.NettyServer$$anonfun$mainDev.apply(NettyServer.scala:165)
~[play_2.9.1.jar:2.0]   at
play.core.server.NettyServer$$anonfun$mainDev.apply(NettyServer.scala:164)
~[play_2.9.1.jar:2.0]   at
play.utils.Threads$.withContextClassLoader(Threads.scala:17)
~[play_2.9.1.jar:2.0]   at
play.core.server.NettyServer$.mainDev(NettyServer.scala:163)
~[play_2.9.1.jar:2.0]

I use the following configuration files:

我使用以下配置文件:

application.conf

应用程序配置文件

db.default.url="postgres://play:play@localhost:9000/Play_Playground_DB"
db.default.user=play
db.default.password=play
db.default.driver=org.postgresql.Driver

project/Build.scala

项目/Build.scala

val appDependencies = Seq(
  "postgresql" % "postgresql" % "9.1-901.jdbc4"
)

I set up Play_Playground_DBand can access it via terminal and the command psql Play_Playground_DB.

我设置Play_Playground_DB并可以通过终端和命令访问它psql Play_Playground_DB

What could be the root cause of the issue?

问题的根本原因可能是什么?

回答by A.H.

Most probably this is the problem:

这很可能是问题所在:

db.default.url="postgres://play:play@localhost:9000/Play_Playground_DB"

The play dokusays, "db.default.url" is a plain JDBC-URL. There are two problems with your value:

游戏数独说,“db.default.url”是一个普通的JDBC的URL。你的值有两个问题:

  • It is not in a format recognized by PostgreSQL. Look herefor allowed formats.
  • With ...default...you redefine the default datasource. By default this calls for trouble unless you do some more steps.
  • 它不是 PostgreSQL 识别的格式。看看这里为允许的格式。
  • 随着...default...您重新定义默认数据源。默认情况下,除非您执行更多步骤,否则这会带来麻烦。

A valid PostgreSQL URL might look like this in your case:

在您的情况下,有效的 PostgreSQL URL 可能如下所示:

jdbc:postgresql://localhost:9000/Play_Playground_DB

But:_Are sure your database is running on port 9000? You say psql Play_Playground_DBworks for you. Therefore I think your port should be the default port 5432. Then this URL is the right one:

但是:_确定您的数据库运行在端口 9000 上吗?你说psql Play_Playground_DB对你有用。因此我认为你的端口应该是默认端口 5432。那么这个 URL 是正确的:

jdbc:postgresql://localhost/Play_Playground_DB

回答by Surge

On my OSX, I've installed PostgreSQL from homebrew and current version is 9.3.4

在我的 OSX 上,我从自制软件安装了 PostgreSQL,当前版本是 9.3.4

The connection strings described above do not work for me because they are using postresqldatabase name. My connections are established if and only if I specify like:

上述连接字符串对我不起作用,因为它们使用的是postresql数据库名称。当且仅当我指定如下时,我的连接才建立:

db.default.url="postgres://user:password@localhost/MyDbName"

Notice that it is postgresinstead of postgresql.

请注意,它是postgres而不是postgresql