Я следую за книгой "Play for Scala". В настоящее время я пытаюсь установить соединение с базой данных PostgreSQL, которую я запускаю на своей машине, однако я не могу подключиться, я не уверен, почему. У моего коллеги есть проект, использующий Play с PostgreSQL, проект клонируется к тому же компьютеру с запуском PostgreSQL, и он работает отлично.Play Framework с Scala, не удается подключиться к базе данных JDBC Postgresql
Я получаю следующее сообщение об ошибке:
[info] - application - Creating Pool for datasource 'default'
[error] - application -
! @6pb6jk4k6 - Internal server error, for (GET) [/products] ->
play.api.Configuration$$anon$1: Configuration error[Cannot connect to database [default]]
at play.api.Configuration$.configError(Configuration.scala:178) ~[play_2.11-2.4.6.jar:2.4.6]
at play.api.Configuration.reportError(Configuration.scala:829) ~[play_2.11-2.4.6.jar:2.4.6]
at play.api.db.DefaultDBApi$$anonfun$connect$1.apply(DefaultDBApi.scala:48) ~[play-jdbc_2.11-2.4.6.jar:2.4.6]
at play.api.db.DefaultDBApi$$anonfun$connect$1.apply(DefaultDBApi.scala:42) ~[play-jdbc_2.11-2.4.6.jar:2.4.6]
at scala.collection.immutable.List.foreach(List.scala:381) ~[scala-library-2.11.7.jar:na]
at play.api.db.DefaultDBApi.connect(DefaultDBApi.scala:42) ~[play-jdbc_2.11-2.4.6.jar:2.4.6]
at play.api.db.DBApiProvider.get$lzycompute(DBModule.scala:72) ~[play-jdbc_2.11-2.4.6.jar:2.4.6]
at play.api.db.DBApiProvider.get(DBModule.scala:62) ~[play-jdbc_2.11-2.4.6.jar:2.4.6]
at play.api.db.DBApiProvider.get(DBModule.scala:58) ~[play-jdbc_2.11-2.4.6.jar:2.4.6]
at com.google.inject.internal.ProviderInternalFactory.provision(ProviderInternalFactory.java:81) ~[guice-4.0.jar:na]
at com.google.inject.internal.BoundProviderFactory.provision(BoundProviderFactory.java:72) ~[guice-4.0.jar:na]
at com.google.inject.internal.ProviderInternalFactory.circularGet(ProviderInternalFactory.java:61) ~[guice-4.0.jar:na]
at com.google.inject.internal.BoundProviderFactory.get(BoundProviderFactory.java:62) ~[guice-4.0.jar:na]
at com.google.inject.internal.SingleFieldInjector.inject(SingleFieldInjector.java:54) ~[guice-4.0.jar:na]
at com.google.inject.internal.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:132) ~[guice-4.0.jar:na]
at com.google.inject.internal.MembersInjectorImpl$1.call(MembersInjectorImpl.java:93) ~[guice-4.0.jar:na]
at com.google.inject.internal.MembersInjectorImpl$1.call(MembersInjectorImpl.java:80) ~[guice-4.0.jar:na]
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1103) ~[guice-4.0.jar:na]
at com.google.inject.internal.MembersInjectorImpl.injectAndNotify(MembersInjectorImpl.java:80) ~[guice-4.0.jar:na]
at com.google.inject.internal.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:62) ~[guice-4.0.jar:na]
at com.google.inject.internal.InjectorImpl.injectMembers(InjectorImpl.java:984) ~[guice-4.0.jar:na]
at com.google.inject.util.Providers$GuicifiedProviderWithDependencies.initialize(Providers.java:149) ~[guice-4.0.jar:na]
at com.google.inject.util.Providers$GuicifiedProviderWithDependencies$$FastClassByGuice$$2a7177aa.invoke(<generated>) ~[guice-4.0.jar:na]
at com.google.inject.internal.cglib.reflect.$FastMethod.invoke(FastMethod.java:53) ~[guice-4.0.jar:na]
at com.google.inject.internal.SingleMethodInjector$1.invoke(SingleMethodInjector.java:57) ~[guice-4.0.jar:na]
at com.google.inject.internal.SingleMethodInjector.inject(SingleMethodInjector.java:91) ~[guice-4.0.jar:na]
at com.google.inject.internal.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:132) ~[guice-4.0.jar:na]
at com.google.inject.internal.MembersInjectorImpl$1.call(MembersInjectorImpl.java:93) ~[guice-4.0.jar:na]
at com.google.inject.internal.MembersInjectorImpl$1.call(MembersInjectorImpl.java:80) ~[guice-4.0.jar:na]
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092) ~[guice-4.0.jar:na]
at com.google.inject.internal.MembersInjectorImpl.injectAndNotify(MembersInjectorImpl.java:80) ~[guice-4.0.jar:na]
at com.google.inject.internal.Initializer$InjectableReference.get(Initializer.java:174) ~[guice-4.0.jar:na]
at com.google.inject.internal.Initializer.injectAll(Initializer.java:108) ~[guice-4.0.jar:na]
at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:174) ~[guice-4.0.jar:na]
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:110) ~[guice-4.0.jar:na]
at com.google.inject.Guice.createInjector(Guice.java:96) ~[guice-4.0.jar:na]
at com.google.inject.Guice.createInjector(Guice.java:73) ~[guice-4.0.jar:na]
at com.google.inject.Guice.createInjector(Guice.java:62) ~[guice-4.0.jar:na]
at play.api.inject.guice.GuiceBuilder.injector(GuiceInjectorBuilder.scala:126) ~[play_2.11-2.4.6.jar:2.4.6]
at play.api.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.scala:93) ~[play_2.11-2.4.6.jar:2.4.6]
at play.api.inject.guice.GuiceApplicationLoader.load(GuiceApplicationLoader.scala:21) ~[play_2.11-2.4.6.jar:2.4.6]
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1$$anonfun$2.apply(DevServerStart.scala:153) ~[play-server_2.11-2.4.6.jar:2.4.6]
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1$$anonfun$2.apply(DevServerStart.scala:150) ~[play-server_2.11-2.4.6.jar:2.4.6]
at play.utils.Threads$.withContextClassLoader(Threads.scala:21) ~[play_2.11-2.4.6.jar:2.4.6]
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(DevServerStart.scala:150) ~[play-server_2.11-2.4.6.jar:2.4.6]
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(DevServerStart.scala:121) ~[play-server_2.11-2.4.6.jar:2.4.6]
at scala.Option.map(Option.scala:146) ~[scala-library-2.11.7.jar:na]
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1.apply(DevServerStart.scala:121) ~[play-server_2.11-2.4.6.jar:2.4.6]
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1.apply(DevServerStart.scala:119) ~[play-server_2.11-2.4.6.jar:2.4.6]
at scala.util.Success.flatMap(Try.scala:231) ~[scala-library-2.11.7.jar:na]
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1.apply(DevServerStart.scala:119) ~[play-server_2.11-2.4.6.jar:2.4.6]
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1.apply(DevServerStart.scala:111) ~[play-server_2.11-2.4.6.jar:2.4.6]
at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24) ~[scala-library-2.11.7.jar:na]
at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24) ~[scala-library-2.11.7.jar:na]
at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402) ~[na:1.8.0_66]
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) ~[na:1.8.0_66]
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056) ~[na:1.8.0_66]
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692) ~[na:1.8.0_66]
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157) ~[na:1.8.0_66]
Caused by: play.api.Configuration$$anon$1: Configuration error[Exception during pool initialization]
at play.api.Configuration$.configError(Configuration.scala:178) ~[play_2.11-2.4.6.jar:2.4.6]
at play.api.PlayConfig.reportError(Configuration.scala:1048) ~[play_2.11-2.4.6.jar:2.4.6]
at play.api.db.HikariCPConnectionPool.create(HikariCPModule.scala:69) ~[play-jdbc_2.11-2.4.6.jar:2.4.6]
at play.api.db.PooledDatabase.createDataSource(Databases.scala:199) ~[play-jdbc_2.11-2.4.6.jar:2.4.6]
at play.api.db.DefaultDatabase.dataSource$lzycompute(Databases.scala:124) ~[play-jdbc_2.11-2.4.6.jar:2.4.6]
at play.api.db.DefaultDatabase.dataSource(Databases.scala:122) ~[play-jdbc_2.11-2.4.6.jar:2.4.6]
at play.api.db.DefaultDatabase.getConnection(Databases.scala:143) ~[play-jdbc_2.11-2.4.6.jar:2.4.6]
at play.api.db.DefaultDatabase.getConnection(Databases.scala:139) ~[play-jdbc_2.11-2.4.6.jar:2.4.6]
at play.api.db.DefaultDBApi$$anonfun$connect$1.apply(DefaultDBApi.scala:44) ~[play-jdbc_2.11-2.4.6.jar:2.4.6]
... 56 common frames omitted
Caused by: com.zaxxer.hikari.pool.PoolInitializationException: Exception during pool initialization
at com.zaxxer.hikari.pool.BaseHikariPool.initializeConnections(BaseHikariPool.java:542) ~[HikariCP-2.3.7.jar:na]
at com.zaxxer.hikari.pool.BaseHikariPool.<init>(BaseHikariPool.java:171) ~[HikariCP-2.3.7.jar:na]
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:60) ~[HikariCP-2.3.7.jar:na]
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:48) ~[HikariCP-2.3.7.jar:na]
at com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:80) ~[HikariCP-2.3.7.jar:na]
at play.api.db.HikariCPConnectionPool$$anonfun$1.apply(HikariCPModule.scala:58) ~[play-jdbc_2.11-2.4.6.jar:2.4.6]
at play.api.db.HikariCPConnectionPool$$anonfun$1.apply(HikariCPModule.scala:54) ~[play-jdbc_2.11-2.4.6.jar:2.4.6]
at scala.util.Try$.apply(Try.scala:192) ~[scala-library-2.11.7.jar:na]
at play.api.db.HikariCPConnectionPool.create(HikariCPModule.scala:54) ~[play-jdbc_2.11-2.4.6.jar:2.4.6]
... 62 common frames omitted
Caused by: java.sql.SQLException: JDBC4 Connection.isValid() method not supported, connection test query must be configured
at com.zaxxer.hikari.pool.BaseHikariPool.addConnection(BaseHikariPool.java:441) ~[HikariCP-2.3.7.jar:na]
at com.zaxxer.hikari.pool.BaseHikariPool.initializeConnections(BaseHikariPool.java:540) ~[HikariCP-2.3.7.jar:na]
... 70 common frames omitted
Вот соответствующий код в application.conf
:
db.default.driver=org.postgresql.Driver
db.default.url="jdbc:postgresql://localhost:5432/paperclips"
db.default.username="postgres"
db.default.password="postgres"
И в файле сборки:
libraryDependencies ++= Seq(
"com.typesafe.play" %% "anorm" % "2.4.0",
"com.adrianhurt" %% "play-bootstrap3" % "0.4.5-P24",
"net.sf.barcode4j" % "barcode4j" % "2.0",
"postgresql" % "postgresql" % "9.1-901.jdbc4"
)
Не могли бы вы разместить сообщение об ошибке? – marcospereira
@marcospereira Обновлен мой вопрос с полным выходом консоли –
Можете ли вы подключиться к локальному postgresql без имени пользователя/пароля? (используя 'psql', для каждого экземпляра). – marcospereira