0

当我尝试运行我的 Play 应用程序时,我目前遇到了错误。它说Failed to load data source,但看起来它确实在加载数据源。我对 Play 和 Scala 非常陌生,我团队的其他成员也是新手,所以如果这是一个愚蠢的错误或者我遗漏了一些代码示例,我深表歉意。app-users具有所有者的数据库root存在于我的本地,我不相信root有密码(使用该createuser工具创建)。

关于可能导致这种情况的任何想法?或者我错过了什么?

错误:

play.api.UnexpectedException: Unexpected exception[IllegalStateException: Failed to load data source for config: 'Config(SimpleConfigObject({"dataSource":"org.postgresql.ds.PGSimpleDataSource","database":"app-users","driver":"org.postgresql.Driver","host":"localhost","password":"","port":5432,"url":"jdbc:postgresql://localhost:5432/app-users","user":"root"}))']
    at play.core.server.DevServerStart$$anon$1.reload(DevServerStart.scala:186)
    at play.core.server.DevServerStart$$anon$1.get(DevServerStart.scala:124)
    at play.core.server.AkkaHttpServer.modelConversion(AkkaHttpServer.scala:183)
    at play.core.server.AkkaHttpServer.handleRequest(AkkaHttpServer.scala:189)
    at play.core.server.AkkaHttpServer.$anonfun$createServerBinding$3(AkkaHttpServer.scala:106)
    at akka.stream.impl.fusing.MapAsync$$anon$24.onPush(Ops.scala:1191)
    at akka.stream.impl.fusing.GraphInterpreter.processPush(GraphInterpreter.scala:512)
    at akka.stream.impl.fusing.GraphInterpreter.processEvent(GraphInterpreter.scala:475)
    at akka.stream.impl.fusing.GraphInterpreter.execute(GraphInterpreter.scala:371)
    at akka.stream.impl.fusing.GraphInterpreterShell.runBatch(ActorGraphInterpreter.scala:584)
Caused by: java.lang.IllegalStateException: Failed to load data source for config: 'Config(SimpleConfigObject({"dataSource":"org.postgresql.ds.PGSimpleDataSource","database":"app-users","driver":"org.postgresql.Driver","host":"localhost","password":"","port":5432,"url":"jdbc:postgresql://localhost:5432/app-users","user":"root"}))'
    at io.getquill.JdbcContextConfig.dataSource(JdbcContextConfig.scala:24)
    at io.getquill.PostgresJdbcContext.<init>(PostgresJdbcContext.scala:17)
    at io.getquill.PostgresJdbcContext.<init>(PostgresJdbcContext.scala:18)
    at io.getquill.PostgresJdbcContext.<init>(PostgresJdbcContext.scala:19)
    at db.db.package$DBContext.<init>(package.scala:6)
    at MyComponents.ctx$lzycompute(MyApplicationLoader.scala:19)
    at MyComponents.ctx(MyApplicationLoader.scala:19)
    at MyComponents.userService$lzycompute(MyApplicationLoader.scala:22)
    at MyComponents.userService(MyApplicationLoader.scala:22)
    at MyComponents.applicationController$lzycompute(MyApplicationLoader.scala:29)
Caused by: java.lang.RuntimeException: java.lang.IllegalArgumentException: argument type mismatch
    at com.zaxxer.hikari.util.PropertyElf.setProperty(PropertyElf.java:154)
    at com.zaxxer.hikari.util.PropertyElf.lambda$setTargetFromProperties$0(PropertyElf.java:57)
    at java.util.Hashtable.forEach(Hashtable.java:879)
    at com.zaxxer.hikari.util.PropertyElf.setTargetFromProperties(PropertyElf.java:52)
    at com.zaxxer.hikari.HikariConfig.<init>(HikariConfig.java:132)
    at io.getquill.JdbcContextConfig.dataSource(JdbcContextConfig.scala:21)
    at io.getquill.PostgresJdbcContext.<init>(PostgresJdbcContext.scala:17)
    at io.getquill.PostgresJdbcContext.<init>(PostgresJdbcContext.scala:18)
    at io.getquill.PostgresJdbcContext.<init>(PostgresJdbcContext.scala:19)
    at db.db.package$DBContext.<init>(package.scala:6)
Caused by: java.lang.IllegalArgumentException: argument type mismatch
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.zaxxer.hikari.util.PropertyElf.setProperty(PropertyElf.java:149)
    at com.zaxxer.hikari.util.PropertyElf.lambda$setTargetFromProperties$0(PropertyElf.java:57)
    at java.util.Hashtable.forEach(Hashtable.java:879)
    at com.zaxxer.hikari.util.PropertyElf.setTargetFromProperties(PropertyElf.java:52)
    at com.zaxxer.hikari.HikariConfig.<init>(HikariConfig.java:132)
    at io.getquill.JdbcContextConfig.dataSource(JdbcContextConfig.scala:21)

应用程序.conf

play.db {
  config = "db"
  default = "default"
}

db.default {
  driver     = "org.postgresql.Driver"
  dataSource = "org.postgresql.ds.PGSimpleDataSource"
  url        = "jdbc:postgresql://localhost:5432/app-users"
  user       = "root"
  user       = ${?DB_USER}
  host       = "localhost"
  host       = ${?DB_HOST}
  port       = 5432
  port       = ${?DB_PORT}
  password   = ""
  password   = ${?DB_PASSWORD}
  database   = "app-users"
}

db/package.scala

import io.getquill.{PostgresJdbcContext, SnakeCase}

package object db {
  class DBContext(config: String) extends PostgresJdbcContext(SnakeCase, config)

  trait Repository {
    val ctx: DBContext
  }
}

使用:

  • 斯卡拉 2.12.4
  • 羽毛笔 2.3.2
  • 玩 2.6.6
  • Postgres JDBC 驱动程序 42.2.1
  • PostgreSQL 10.2

更新:为 root 用户添加了“root”密码并切换到使用与Quill 文档相同的格式,所以现在 appliation.conf 看起来像这样:

db.default {
    dataSourceClassName = org.postgresql.ds.PGSimpleDataSource
    dataSource.user = root
    dataSource.password = root
    dataSource.databaseName = app-users
    dataSource.portNumber = 5432
    dataSource.serverName = host
    connectionTimeout = 30000
}

但是报错信息还是基本一样的:

play.api.UnexpectedException: Unexpected exception[IllegalStateException: Failed to load data source for config: 'Config(SimpleConfigObject({"connectionTimeout":30000,"dataSource":{"databaseName":"app-users","password":"root","portNumber":5432,"serverName":"host","user":"root"},"dataSourceClassName":"org.postgresql.ds.PGSimpleDataSource"}))']
4

1 回答 1

1

以下对我有用:

db.default {
    dataSourceClassName = org.postgresql.ds.PGSimpleDataSource
    dataSource.user = root
    dataSource.password = root
    dataSource.databaseName = app-users
    dataSource.portNumber = 5432
    dataSource.serverName = localhost
    connectionTimeout = 30000
}

基本上,localhost而不是host. 我猜第一次迭代没有工作,因为引号。

于 2018-03-01T14:38:31.503 回答