我的play-framework项目在本地运行良好,但是当我尝试在heroku中部署它时,出现以下错误。
2015-07-05T06:24:10.456657+00:00 app[web.1]: at com.google.inject.Guice.createInjector(Guice.java:73)
2015-07-05T06:24:10.456817+00:00 app[web.1]: at play.api.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.scala:93)
2015-07-05T06:24:10.456702+00:00 app[web.1]: at com.google.inject.Guice.createInjector(Guice.java:62)
2015-07-05T06:24:10.456746+00:00 app[web.1]: at play.api.inject.guice.GuiceBuilder.injector(GuiceInjectorBuilder.scala:126)
2015-07-05T06:24:10.456863+00:00 app[web.1]: at play.api.inject.guice.GuiceApplicationLoader.load(GuiceApplicationLoader.scala:21)
2015-07-05T06:24:10.456909+00:00 app[web.1]: at play.core.server.ProdServerStart$.start(ProdServerStart.scala:52)
2015-07-05T06:24:10.456951+00:00 app[web.1]: at play.core.server.ProdServerStart$.main(ProdServerStart.scala:27)
2015-07-05T06:24:10.456994+00:00 app[web.1]: at play.core.server.ProdServerStart.main(ProdServerStart.scala)
2015-07-05T06:24:10.457407+00:00 app[web.1]: at com.zaxxer.hikari.pool.BaseHikariPool.addConnection(BaseHikariPool.java:441)
2015-07-05T06:24:10.457496+00:00 app[web.1]: at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
2015-07-05T06:24:10.457369+00:00 app[web.1]: Caused by: java.sql.SQLException: JDBC4 Connection.isValid() method not supported, connection test query must be configured
2015-07-05T06:24:10.457602+00:00 app[web.1]: at java.util.concurrent.FutureTask.run(FutureTask.java:266)
2015-07-05T06:24:10.457451+00:00 app[web.1]: at com.zaxxer.hikari.pool.BaseHikariPool$1.run(BaseHikariPool.java:413)
2015-07-05T06:24:10.457681+00:00 app[web.1]: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
2015-07-05T06:24:10.457812+00:00 app[web.1]: at java.lang.Thread.run(Thread.java:745)
2015-07-05T06:24:10.457768+00:00 app[web.1]: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
2015-07-05T06:24:11.231007+00:00 heroku[web.1]: Process exited with status 255
2015-07-05T06:24:11.243795+00:00 heroku[web.1]: State changed from starting to crashed
2015-07-05T06:24:11.245013+00:00 heroku[web.1]: State changed from crashed to starting
2015-07-05T06:24:16.259302+00:00 heroku[web.1]: Starting process with command `target/universal/stage/bin/sazors -Dhttp.port=10803`
2015-07-05T06:24:17.542815+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx384m -Xss512k -Dfile.encoding=UTF-8
2015-07-05T06:24:18.643391+00:00 app[web.1]: 06:24:18,391 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
2015-07-05T06:24:18.643397+00:00 app[web.1]: 06:24:18,391 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
我使用PostgreSQL作为数据库,使用slick作为数据库访问库。我尝试用Google搜索它,经过一些研究,我发现当配置文件中提供的网址不正确或返回null时,可能导致此错误。我试图修复它,但无法解决此错误。
这是我的Procfile:
和Application.conf
slick.dbs.default.driver="slick.driver.PostgresDriver$"
slick.dbs.default.db.driver="org.postgresql.Driver"
slick.dbs.default.db.url="postgres://rycmvicwkkzofh:Xt2PWggm__FQEHOeq9EoMqTOtF@ec2-54-243-132-114.compute-1.amazonaws.com:5432/d5pr4h65obtb0s"
slick.dbs.default.db.user=rycmuicwkkzofh
slick.dbs.default.db.password="copiedfromheroku"
附注:我正在研究这些修订
play framework version : 2.4.0 slick version : 3.0
编辑:如果我在我的application.conf中添加
slick.dbs.default.db.connectionTestQuery="SELECT 1"
,它将产生新的nullPointerException错误类型。That is gone but getting new error now:
2015-07-05T12:22:49.781133+00:00 app[web.1]: at com.google.inject.Guice.createInjector(Guice.java:73)
2015-07-05T12:22:49.781201+00:00 app[web.1]: at com.google.inject.Guice.createInjector(Guice.java:62)
2015-07-05T12:22:49.781283+00:00 app[web.1]: at play.api.inject.guice.GuiceBuilder.injector(GuiceInjectorBuilder.scala:126)
2015-07-05T12:22:49.781361+00:00 app[web.1]: at play.api.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.scala:93)
2015-07-05T12:22:49.781507+00:00 app[web.1]: at play.core.server.ProdServerStart$.start(ProdServerStart.scala:52)
2015-07-05T12:22:49.781425+00:00 app[web.1]: at play.api.inject.guice.GuiceApplicationLoader.load(GuiceApplicationLoader.scala:21)
2015-07-05T12:22:49.781599+00:00 app[web.1]: at play.core.server.ProdServerStart$.main(ProdServerStart.scala:27)
2015-07-05T12:22:49.781669+00:00 app[web.1]: at play.core.server.ProdServerStart.main(ProdServerStart.scala)
2015-07-05T12:22:49.782161+00:00 app[web.1]: Caused by: java.lang.NullPointerException
2015-07-05T12:22:49.782226+00:00 app[web.1]: at com.zaxxer.hikari.pool.BaseHikariPool.addConnection(BaseHikariPool.java:446)
2015-07-05T12:22:49.782328+00:00 app[web.1]: at com.zaxxer.hikari.pool.BaseHikariPool$1.run(BaseHikariPool.java:413)
2015-07-05T12:22:49.782417+00:00 app[web.1]: at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
2015-07-05T12:22:49.782515+00:00 app[web.1]: at java.util.concurrent.FutureTask.run(FutureTask.java:266)
2015-07-05T12:22:49.783691+00:00 app[web.1]: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
2015-07-05T12:22:49.783803+00:00 app[web.1]: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
2015-07-05T12:22:49.783883+00:00 app[web.1]: at java.lang.Thread.run(Thread.java:745)
最佳答案
我相信这个问题已经在the Play mailing list here上进行了讨论。
原因是Slick不支持Heroku设置的DATABASE_URL格式。您将必须将DATABASE_URL解析为JDBC URL。您可以使用heroku-jdbc库轻松完成此操作:
https://github.com/jkutner/heroku-jdbc
只需在您的部门中添加这样的一行即可:
libraryDependencies += "com.heroku.sdk" % "heroku-jdbc" % "0.1.0"
然后,您可以像这样解析网址:
var jdbcURL = DatabaseUrl.extract.jdbcUrl
然后将该网址传递给Slick
编辑
实际上,似乎大多数人都在手动解析DATABASE_URL,并使用硬编码值设置光滑的conf。很好,但是请注意,连接可能会更改,因此您必须手动更改设置。
因此,您需要将配置更改为此:
slick.dbs.default.db.url="jdbc:postgresql://host:port/path"
但是您可能想要销毁并重新创建数据库,因为您已将连接详细信息公开发布。
我已经提交了一份PR,以解决此问题:
https://github.com/slick/slick/pull/1193
关于scala - 由: java. sql.SQLException引起的: JDBC4 Connection. isValid()方法不受支持,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31228074/