玩框架+ Heroku + Postgres无法连接 [英] Play Framework + Heroku + Postgres not able to connect

查看:107
本文介绍了玩框架+ Heroku + Postgres无法连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经有一段时间让我玩了!框架java应用程序在Heroku上运行,我想我已经缩小到不喜欢Heroku的DATABASE_URL参数的Postgres JDBC驱动程序,因为它以postgres开头:而不是postgresql:。



配置游戏的正确方法是什么! 2.0应用程序连接到一个heroku提供的Postgres实例?

我尝试了以下变体:
PLAY_OPTS = - Ddb.default.url = $ DATABASE_URL -Ddb.default.driver = org.postgresql .Driver



但是在启动时,我得到了一个SQLException,显示$ DATABASE_URL中找不到合适的驱动程序。

解决方案

无需将它们作为系统属性传递,您可以在 application.conf 文件中获取Heroku环境变量

  ... 
db.default.driver = org.postgresql.Driver
db.default.url = $ {DATABASE_URL }

然后在你的 Procfile

  web:target / start -Dhttp.port = $ {PORT} $ {JAVA_OPTS} -Dconfig.resource = application.conf 

它应该选取 DATABASE_URL 属性Heroku环境。尽管我建议创建一个特定于Heroku环境的配置文件(即heroku-prod.conf),但这仅仅是一个例子。


I've been having a heck of a time getting my Play! framework java app to run on Heroku, and I think I've narrowed it down to the Postgres JDBC driver not liking Heroku's DATABASE_URL parameter because it starts with postgres: and not postgresql:.

What is the proper way to configure a play! 2.0 app to connect to a heroku-provided Postgres instance?

I've tried variations on the following: PLAY_OPTS="-Ddb.default.url=$DATABASE_URL -Ddb.default.driver=org.postgresql.Driver"

But upon startup I get a SQLException that no suitable driver can be found for $DATABASE_URL.

解决方案

No need to pass them in as system properties you can pickup Heroku environment variables in your application.conf file

...
db.default.driver=org.postgresql.Driver
db.default.url=${DATABASE_URL}

Then define this in your Procfile

web: target/start -Dhttp.port=${PORT} ${JAVA_OPTS} -Dconfig.resource=application.conf

It should pick up the DATABASE_URL property for the Heroku environment. Although, I recommend creating a configuration file that is specific for the Heroku environment (i.e. heroku-prod.conf), but this is just an example.

这篇关于玩框架+ Heroku + Postgres无法连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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