问题描述
我收到了
CreationException:无法创建注入器,请看以下错误:
1)错误在定制提供程序中,配置错误:配置错误[无法连接到数据库[默认]]
[...]
2) ]]
完整堆栈跟踪位于此处:
最初我有MySQL数据库用于Play Framework应用程序它工作,但我想把它改为PostgreSQL,这就是问题开始出现。我已经安装他们在我的Ubuntu计算机和更改播放配置使用Postgres(添加postgresql%postgresql%9.1-901-1.jdbc4,
到build.sbt并更改了db.default属性来引用Postgres)。 Exact application.conf
是:
db.default.driver = orgbost.result.Driver
db.default.url =jdbc:postgres:// localhost:5432 / playdb
db.default.username =luka
db.default。 password =test
$ b $ p我已手动创建了用户luka和密码测试和数据库playdb。我已经尝试与postgres用户,以及没有效果。
更糟的是,MySQL不会工作,现在有相同的错误。我已经创建了新的项目,只修改了conf中的db.default参数,并且它以相同的方式失败。注释 application.conf
会使它消失,这绝对是个问题。我已经检查PostgreSQL日志( /var/log/postgresql/postgresql-9.4-main.log
),只有不正确的行是 [unknown] @ [unknown] LOG:启动包长度无效
。它出现多次,但不是每次刷新项目(我甚至不确定它是相关的)。我已经从我的PC中删除了 mysql-server
希望一切都会魔法修复自己。它没有。
想法?
我使用Play 2. 4. 6和IntelliJ IDEA 15.创建项目
编辑当我添加 db.default.hikaricp时,使用Activator并导入源到IDEA .connectionTestQuery =SELECT 1
到我的 application.conf
,我得到以下错误: 因此,确定的答案是:
首先,数据库url有一个错误,应该是 db.default.url =作为的jdbc:postgresql:// localhost:5432 / playdb
这是 db.default.url
(所以没有 jdbc:postgresql://用户名:pasword:localhost / dbname
或类似,因为我已经看到在其他地方建议。)
第二,更棘手,是有一个错误在驱动程序,解决方法是添加 db.default.hikaricp.connectionTestQuery =SELECT 1
到 application.conf
。
然而,该bug是固定的(以及实施解决方法) c> 9.1-903 。 catch是在版本 9.1-901
之后postgresql在repos中更改了其groupID,现在它被 org.postgresql
。一个比解决方法更好的解决方案是更新依赖项到org.postgresql%postgresql%9.4-1206-jdbc4
()。将适当的jdbc版本附加到最新的PostgreSQL驱动程序(对于Java 6, 4
,对于Java 7, 41
我的最后 application.conf
:
db.default.driver =org.postgresql.Driver
db.default.url =jdbc :postgresql:// localhost / playdb#端口是可选的
db.default.username =luka
db.default.password =test
和 libraryDependencies
in build.sbt
:
libraryDependencies ++ = Seq(
jdbc,
org.postgresql%postgresql %9.4-1206-jdbc42,
cache,
javaWs
)
I'm getting
CreationException: Unable to create injector, see the following errors:
1) Error in custom provider, Configuration error: Configuration error[Cannot connect to database [default]]
[...]
2) Error in custom provider, Configuration error: Configuration error[Cannot connect to database [default]]
Full stack trace is here: http://hastebin.com/ahacepifaf.txt
Originally I had MySQL database used with Play Framework app which worked, but I wanted to change it to PostgreSQL and that's when problems started appearing. I've installed them both on my Ubuntu computer and changed play config to use Postgres (added "postgresql" % "postgresql" % "9.1-901-1.jdbc4",
to build.sbt and changed db.default properties to reference Postgres). Exact application.conf
is:
db.default.driver="org.postgresql.Driver"
db.default.url="jdbc:postgres://localhost:5432/playdb"
db.default.username="luka"
db.default.password="test"
I have manually created user luka with password test and database playdb. I have tried with postgres user as well with no avail.
What bugs me more, MySQL won't work either now with the same error. I have created new project with only modifying db.default params in conf and it fails in the same manner. Commenting out application.conf
makes it go away, so that's definitely the problem. I have checked PostgreSQL logs (/var/log/postgresql/postgresql-9.4-main.log
) and only line that doesn't seem right is [unknown]@[unknown] LOG: invalid length of startup packet
. It appears multiple times, but not every time I refresh project (I'm not even sure it's related). I have removed mysql-server
from my PC hoping everything will magically fix itself. It didn't.
Ideas?
I'm using Play 2. 4. 6 and IntelliJ IDEA 15. Project is created using Activator and importing sources to IDEA (using SBT model).
EDIT When I add db.default.hikaricp.connectionTestQuery = "SELECT 1"
to my application.conf
, I get the following error: http://hastebin.com/hazoraradi.txt
So, the definite answer is:
First, there's a mistake in the database url, it should be db.default.url="jdbc:postgresql://localhost:5432/playdb"
as chabeee pointed out. It's the only correct format for db.default.url
(so no jdbc:postgresql://username:pasword:localhost/dbname
or similar, as I've seen suggesting on other places).
Second, more tricky, is that there's a bug in the driver as Salem pointed out and workaround is adding db.default.hikaricp.connectionTestQuery = "SELECT 1"
to application.conf
.
However, that bug is fixed (well, that workaround is implemented) in versions more recent than 9.1-903
. The catch is, after version 9.1-901
postgresql changed its groupID in the repos and now it's referenced by org.postgresql
. A better solution than the workaround would be updating dependencies to "org.postgresql" % "postgresql" % "9.4-1206-jdbc4"
(current version). Append the appropriate jdbc version to the most recent PostgreSQL driver (4
for Java 6, 41
for Java 7, 42
for Java 8).
My final application.conf
:
db.default.driver="org.postgresql.Driver"
db.default.url="jdbc:postgresql://localhost/playdb" #the port is optional
db.default.username="luka"
db.default.password="test"
And libraryDependencies
in build.sbt
:
libraryDependencies ++= Seq(
jdbc,
"org.postgresql" % "postgresql" % "9.4-1206-jdbc42",
cache,
javaWs
)
这篇关于播放无法连接到数据库[默认]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!