使用Play Framework 2.2.2无法连接到远程Heroku Postgres数据库 [英] Cannot connect to remote Heroku Postgres database using Play Framework 2.2.2

查看:157
本文介绍了使用Play Framework 2.2.2无法连接到远程Heroku Postgres数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Heroku帐户,并且我创建了一个应用程序和一个Heroku-Postgres数据库。
我已经将应用程序提交给Heroku云,但我无法访问我创建的数据库。



我正在使用play,当我连接我的项目在我的本地数据库中,application.conf配置为:

  db.default.driver = org.postgresql.Driver 
db.default.url =jdbc:postgresql:// localhost:5432 / postgres
db.default.user = postgres
db.default.password =密码
code>

并且在本地运行我的服务器并且工作正常。



在我之前上传我的应用程序到Heroku我改变了这个文件来访问我的Heroku-Postgres数据库:
$ b db.default.driver = org.postgresql.Driver
db.default .url =jdbc:postgresql:// url:5432 / database_name?user = name& password = pass& ssl = true& sslfactory = org.postgresql.ssl.NonValidatingFactory



用户和密码字段不再需要。我已经在名为Procfile的项目的根目录中创建了一个文件,该文件包含以下内容:

  web:target / universal / stage / bin / playsense -Dhttp.port = $ {PORT} -DapplyEvolutions.default = true -Ddb.default.driver = org.postgresql.Driver -Ddb.default.url = $ {DATABASE_URL} 

我在文档中发现了这一点。我不明白为什么它不连接到我的数据库。
我使用了pgAdminIII和DB凭证,它工作的很好。



这是缺少的/错误的东西,我不知道。



有人可以帮我吗?提前致谢!

解决方案

您可能需要取消设置 db.default.user db.default.password config params。但我不确定一个简单的方法来做到这一点。所以我通常做的就是不把它们设置在 conf / application.conf 中,而是像这样做:

  db.default.driver = org.postgresql.Driver 
db.default.url =postgres:// postgres:password @ localhost:5432 / postgres
db.default.url = $ {?DATABASE_URL}
#db.default.user = postgres
#db.default.password =密码
$ b

它提供了一个默认的 db.default.url ,但是用 DATABASE_URL env var如果已设置。


I have an Heroku account and i created an app and an Heroku-Postgres database. I already commited the app to the Heroku cloud, but i cannot access to the DB that i created.

I'm using play, and when i connect my project in my local DB, the application.conf configurations are:

db.default.driver=org.postgresql.Driver
db.default.url="jdbc:postgresql://localhost:5432/postgres"
db.default.user=postgres
db.default.password=password

And run my server locally and it works fine.

Before i upload my app to Heroku i changed this file to access my Heroku-Postgres DB:

db.default.driver=org.postgresql.Driver db.default.url="jdbc:postgresql://url:5432/database_name?user=name&password=pass&ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory"

The user and password fields are no longer needed. I've already created a file in the root of my project named "Procfile" that has:

web: target/universal/stage/bin/playsense -Dhttp.port=${PORT} -DapplyEvolutions.default=true -Ddb.default.driver=org.postgresql.Driver -Ddb.default.url=${DATABASE_URL}

I discovered this on the documentation. I don't understand why it doesn't connect to my DB. I used pgAdminIII with the DB credentials and it works fine.

It's something missing/wrong and i don't know what.

Can someone help me? Thanks in advance!

解决方案

You probably need to unset the db.default.user and db.default.password config params when running on Heroku. But I'm not sure of an easy way to do that. So what I usually do is to not set them in the conf/application.conf and instead I do something like:

db.default.driver=org.postgresql.Driver
db.default.url="postgres://postgres:password@localhost:5432/postgres"
db.default.url=${?DATABASE_URL}
#db.default.user=postgres
#db.default.password=password

That provides a default db.default.url but overrides it with the DATABASE_URL env var if it is set.

这篇关于使用Play Framework 2.2.2无法连接到远程Heroku Postgres数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆