播放无法连接到(PostgreSQL)数据库[​​默认]

播放无法连接到(PostgreSQL)数据库[​​默认],第1张

概述我越来越 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 我越来越
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]]

最初我使用了与Play Framework应用程序一起工作的MysqL数据库,但是我想把它改成Postgresql,那就是问题开始出现的时候.我已经在我的Ubuntu计算机上安装了它们并更改了播放配置以使用Postgres(添加了“postgresql”%“postgresql”%“9.1-901-1.jdbc4”,以构建.sb并更改了db.default属性以引用Postgres ).确切的application.conf是:

db.default.driver="org.postgresql.Driver"db.default.url="jdbc:postgres://localhost:5432/playdb"db.default.username="luka"db.default.password="test"

我已手动创建用户luka与密码测试和数据库playdb.我已经尝试过postgres用户也无济于事.

更让我感到困扰的是,MysqL现在无法使用相同的错误.我创建了一个新项目,只修改了conf中的db.default参数,它以同样的方式失败.注释掉application.conf会让它消失,所以这肯定是问题所在.我检查了Postgresql日志(/var/log/postgresql/postgresql-9.4-main.log),只有看起来不正确的行是[未知] @ [未知] LOG:启动数据包的长度无效.它出现多次,但不是每次我刷新项目(我甚至不确定它是否相关).我已经从我的电脑中删除了MysqL-server,希望一切都能神奇地修复自己.它没有.

想法?

我正在使用Play 2. 4. 6和IntelliJ IDEA 15.使用Activator创建项目并将源导入IDEA(使用SBT模型).

编辑我将db.default.hikaricp.connectionTestquery =“SELECT 1”添加到我的application.conf时也遇到错误.

所以,明确的答案是:

首先,数据库url中有一个错误,它应该是db.default.url =“jdbc:postgresql:// localhost:5432 / playdb”为chabeee pointed out.这是db.default.url唯一正确的格式(所以没有jdbc :postgresql://用户名:pasword:localhost / dbname或类似的,正如我在其他地方看到的那样建议).

第二,更棘手的是,驱动程序中有一个错误,因为Salem pointed out和解决方法是将db.default.hikaricp.connectionTestquery =“SELECT 1”添加到application.conf.
但是,在比9.1-903更新的版本中修复了这个错误(好了,解决方法已经实现).问题是,在版本9.1-901之后,postgresql在repos中更改了它的groupID,现在它被org.postgresql引用.比解决方法更好的解决方案是将依赖关系更新为“org.postgresql”%“postgresql”%“9.4-1206-jdbc4”(current version,MVNrepository).将适当的jdbc版本附加到最新的Postgresql驱动程序(4个用于Java 6,41个用于Java 7,42个用于Java 8).

我最后的application.conf:

db.default.driver="org.postgresql.Driver"db.default.url="jdbc:postgresql://localhost/playdb" #the port is optionaldb.default.username="luka"db.default.password="test"

和build.sbt中的libraryDependencIEs:

libraryDependencIEs ++= Seq(  jdbc,"org.postgresql" % "postgresql" % "9.4-1206-jdbc42",cache,javaWs)

2017年更新:
我现在才注意到,在写完这个答案后不久,他们改变了版本控制方案并删除了-jdbc [code]片段,将其替换为.jre6,.jre7或者什么也没有,显然意味着它适用于最新的Java版本(我没有发现支持这种说法的任何东西,但它确实有效).然而在2017年2月它们又是changed the version scheme again并从主要版本9跳到42,使当前版本(截至2017年7月17日)表示为“org.postgresql”%“postgresql”%“42.1.3”(或相应地,“ org.postgresql“%”postgresql“%”42.1.3.jre7“/”org.postgresql“%”postgresql“%”42.1.3.jre6“)

总结

以上是内存溢出为你收集整理的播放无法连接到(PostgreSQL)数据库[​​默认]全部内容,希望文章能够帮你解决播放无法连接到(PostgreSQL)数据库[​​默认]所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/1170520.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-02
下一篇 2022-06-02

发表评论

登录后才能评论

评论列表(0条)

保存