首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未能使用Play-2.6和Quill.io加载配置数据源

未能使用Play-2.6和Quill.io加载配置数据源
EN

Stack Overflow用户
提问于 2018-02-28 15:34:43
回答 1查看 793关注 0票数 0

目前,当我试图运行我的Play应用程序时,我遇到了一个错误。它写着Failed to load data source,但是看起来它确实是在加载数据源。我是新手,Scala和我的团队其他成员也是新的,所以如果这是一个愚蠢的错误,或者如果我缺少一些代码示例,那么请原谅。我的本地存在带有所有者root的数据库root,我认为root没有密码(使用createuser工具创建)。

有什么能导致这件事的想法吗?或者我错过了什么?

错误:

代码语言:javascript
复制
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)

application.conf

代码语言:javascript
复制
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

代码语言:javascript
复制
import io.getquill.{PostgresJdbcContext, SnakeCase}

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

  trait Repository {
    val ctx: DBContext
  }
}

使用:

  • Scala 2.12.4
  • 奎尔2.3.2
  • 播放2.6.6
  • Postgres JDBC驱动程序42.2.1
  • PostgreSQL 10.2

更新:向根用户添加了一个" root“密码,并切换到使用与奎尔博士相同的格式,因此现在appliation.conf如下所示:

代码语言:javascript
复制
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
}

但是,错误信息仍然基本相同:

代码语言:javascript
复制
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"}))']
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-03-01 14:38:31

以下几点对我有用:

代码语言:javascript
复制
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。我猜第一次迭代不起作用是因为引号。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49033199

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档