无法使用Play-2.6和Quill.io加载配置的数据源

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了无法使用Play-2.6和Quill.io加载配置的数据源相关的知识,希望对你有一定的参考价值。

我在尝试运行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)

application.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 /包

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 docs相同的格式,所以现在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"}))']
答案

以下对我有用:

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。我猜第一次迭代因为引号而无效。

以上是关于无法使用Play-2.6和Quill.io加载配置的数据源的主要内容,如果未能解决你的问题,请参考以下文章

在Play 2.6的conf文件中Hikari,Quill和Postgres之间的冲突

播放框架 2.6:NoClassDefFoundError:播放/缓存/DefaultCacheApi

如何在 Play 2.6 控制器中使“CustomExecutionContext”可用于依赖注入?

解决Docker Mysql无法正确加载配置文件

python selenium 无法使用 Firefox 扩展 - 消息:无法加载配置文件。简介目录

Python3.5 和 FF48 的 Selenium WebDriver 出现“无法加载配置文件”错误