我完成了“Getting Started on Heroku with Scala and Play”教程,我的应用似乎在本地和部署环境中都能正常运行。我正在试图弄清楚如何为我在运行heroku local
时使用的应用程序设置一个单独的本地postgres数据库,而不是让它使用与实时应用程序使用的数据库相同的数据库。
我在Mac上并通过自制软件安装了scala和sbt。我在本地下载了postgres并尝试在.env文件中设置DATABASE_URL=postgres://$(whoami)
以尝试将其指向默认数据库,但是我收到以下错误:
$ heroku local web
[OKAY] Loaded ENV .env File as KEY=VALUE Format
19:01:50 web.1 | [warn] application - Logger configuration in conf files is deprecated and has no effect. Use a logback configuration file instead.
19:01:50 web.1 | [info] application - Creating Pool for datasource 'default'
19:01:51 web.1 | Oops, cannot start the server.
19:01:51 web.1 | Configuration error: Configuration error[Cannot connect to database [default]]
19:01:51 web.1 | at play.api.Configuration$.configError(Configuration.scala:178)
19:01:51 web.1 | at play.api.Configuration.reportError(Configuration.scala:829)
19:01:51 web.1 | at play.api.db.DefaultDBApi$$anonfun$connect$1.apply(DefaultDBApi.scala:48)
19:01:51 web.1 | at play.api.db.DefaultDBApi$$anonfun$connect$1.apply(DefaultDBApi.scala:42)
19:01:51 web.1 | at scala.collection.immutable.List.foreach(List.scala:381)
19:01:51 web.1 | at play.api.db.DefaultDBApi.connect(DefaultDBApi.scala:42)
19:01:51 web.1 | at play.api.db.DBApiProvider.get$lzycompute(DBModule.scala:72)
19:01:51 web.1 | at play.api.db.DBApiProvider.get(DBModule.scala:62)
19:01:51 web.1 | at play.api.db.DBApiProvider.get(DBModule.scala:58)
19:01:51 web.1 | at com.google.inject.internal.ProviderInternalFactory.provision(ProviderInternalFactory.java:81)
19:01:51 web.1 | at com.google.inject.internal.BoundProviderFactory.provision(BoundProviderFactory.java:72)
19:01:51 web.1 | at com.google.inject.internal.ProviderInternalFactory.circularGet(ProviderInternalFactory.java:61)
19:01:51 web.1 | at com.google.inject.internal.BoundProviderFactory.get(BoundProviderFactory.java:62)
19:01:51 web.1 | at com.google.inject.internal.SingleFieldInjector.inject(SingleFieldInjector.java:54)
19:01:51 web.1 | at com.google.inject.internal.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:132)
19:01:51 web.1 | at com.google.inject.internal.MembersInjectorImpl$1.call(MembersInjectorImpl.java:93)
19:01:51 web.1 | at com.google.inject.internal.MembersInjectorImpl$1.call(MembersInjectorImpl.java:80)
19:01:51 web.1 | at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1103)
19:01:51 web.1 | at com.google.inject.internal.MembersInjectorImpl.injectAndNotify(MembersInjectorImpl.java:80)
19:01:51 web.1 | at com.google.inject.internal.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:62)
19:01:51 web.1 | at com.google.inject.internal.InjectorImpl.injectMembers(InjectorImpl.java:984)
19:01:51 web.1 | at com.google.inject.util.Providers$GuicifiedProviderWithDependencies.initialize(Providers.java:149)
19:01:51 web.1 | at com.google.inject.util.Providers$GuicifiedProviderWithDependencies$$FastClassByGuice$$2a7177aa.invoke(<generated>)
19:01:51 web.1 | at com.google.inject.internal.cglib.reflect.$FastMethod.invoke(FastMethod.java:53)
19:01:51 web.1 | at com.google.inject.internal.SingleMethodInjector$1.invoke(SingleMethodInjector.java:57)
19:01:51 web.1 | at com.google.inject.internal.SingleMethodInjector.inject(SingleMethodInjector.java:91)
19:01:51 web.1 | at com.google.inject.internal.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:132)
19:01:51 web.1 | at com.google.inject.internal.MembersInjectorImpl$1.call(MembersInjectorImpl.java:93)
19:01:51 web.1 | at com.google.inject.internal.MembersInjectorImpl$1.call(MembersInjectorImpl.java:80)
19:01:51 web.1 | at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092)
19:01:51 web.1 | at com.google.inject.internal.MembersInjectorImpl.injectAndNotify(MembersInjectorImpl.java:80)
19:01:51 web.1 | at com.google.inject.internal.Initializer$InjectableReference.get(Initializer.java:174)
19:01:51 web.1 | at com.google.inject.internal.Initializer.injectAll(Initializer.java:108)
19:01:51 web.1 | at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:174)
19:01:51 web.1 | at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:110)
19:01:51 web.1 | at com.google.inject.Guice.createInjector(Guice.java:96)
19:01:51 web.1 | at com.google.inject.Guice.createInjector(Guice.java:73)
19:01:51 web.1 | at com.google.inject.Guice.createInjector(Guice.java:62)
19:01:51 web.1 | at play.api.inject.guice.GuiceBuilder.injector(GuiceInjectorBuilder.scala:126)
19:01:51 web.1 | at play.api.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.scala:93)
19:01:51 web.1 | at play.api.inject.guice.GuiceApplicationLoader.load(GuiceApplicationLoader.scala:21)
19:01:51 web.1 | at play.core.server.ProdServerStart$.start(ProdServerStart.scala:52)
19:01:51 web.1 | at play.core.server.ProdServerStart$.main(ProdServerStart.scala:27)
19:01:51 web.1 | at play.core.server.ProdServerStart.main(ProdServerStart.scala)
19:01:51 web.1 | Caused by: Configuration error: Configuration error[Exception during pool initialization]
19:01:51 web.1 | at play.api.Configuration$.configError(Configuration.scala:178)
19:01:51 web.1 | at play.api.PlayConfig.reportError(Configuration.scala:1048)
19:01:51 web.1 | at play.api.db.HikariCPConnectionPool.create(HikariCPModule.scala:69)
19:01:51 web.1 | at play.api.db.PooledDatabase.createDataSource(Databases.scala:199)
19:01:51 web.1 | at play.api.db.DefaultDatabase.dataSource$lzycompute(Databases.scala:124)
19:01:51 web.1 | at play.api.db.DefaultDatabase.dataSource(Databases.scala:122)
19:01:51 web.1 | at play.api.db.DefaultDatabase.getConnection(Databases.scala:143)
19:01:51 web.1 | at play.api.db.DefaultDatabase.getConnection(Databases.scala:139)
19:01:51 web.1 | at play.api.db.DefaultDBApi$$anonfun$connect$1.apply(DefaultDBApi.scala:44)
19:01:51 web.1 | ... 41 more
19:01:51 web.1 | Caused by: com.zaxxer.hikari.pool.PoolInitializationException: Exception during pool initialization
19:01:51 web.1 | at com.zaxxer.hikari.pool.BaseHikariPool.initializeConnections(BaseHikariPool.java:542)
19:01:51 web.1 | at com.zaxxer.hikari.pool.BaseHikariPool.<init>(BaseHikariPool.java:171)
19:01:51 web.1 | at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:60)
19:01:51 web.1 | at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:48)
19:01:51 web.1 | at com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:80)
19:01:51 web.1 | at play.api.db.HikariCPConnectionPool$$anonfun$1.apply(HikariCPModule.scala:58)
19:01:51 web.1 | at play.api.db.HikariCPConnectionPool$$anonfun$1.apply(HikariCPModule.scala:54)
19:01:51 web.1 | at scala.util.Try$.apply(Try.scala:192)
19:01:51 web.1 | at play.api.db.HikariCPConnectionPool.create(HikariCPModule.scala:54)
19:01:51 web.1 | ... 47 more
19:01:51 web.1 | Caused by: java.sql.SQLException: JDBC4 Connection.isValid() method not supported, connection test query must be configured
19:01:51 web.1 | at com.zaxxer.hikari.pool.BaseHikariPool.addConnection(BaseHikariPool.java:441)
19:01:51 web.1 | at com.zaxxer.hikari.pool.BaseHikariPool.initializeConnections(BaseHikariPool.java:540)
19:01:51 web.1 | ... 55 more
19:01:51 web.1 Exited with exit code 255
答案 0 :(得分:1)
尝试将DATABASE_URL设置为JDBC URL,如:
DATABASE_URL=jdbc:postgresql://localhost:5432/$(whoami)