无法使用Play-2.6和Quill.io加载配置的数据源 [英] Failed to load data source for config using Play-2.6 and Quill.io

查看:90
本文介绍了无法使用Play-2.6和Quill.io加载配置的数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试运行Play应用时,我目前遇到错误.它说Failed to load data source,但是看起来确实确实在加载数据源.我是Play和Scala的新手,而我团队的其他成员也是新手,因此,如果这是一个愚蠢的错误,或者如果我缺少一些代码示例,则深表歉意.所有者为root的数据库app-users存在于我的本地计算机上,我不相信root具有密码(使用createuser工具创建).

I'm currently getting an error when I try to run my Play app. It says Failed to load data source but then it looks like it is indeed loading the data source. I'm very new to Play and Scala and the rest of my team is also new, so apologies if this is a silly error or if I'm missing some code samples. Database app-users with owner root exists on my local and I don't believe root has a password (created using the createuser tool).

关于什么可能导致这种情况的任何想法?还是我想念的东西?

Any ideas on what could cause this? Or what I am missing?

错误:

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

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/package.scala

db/package.scala

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
  • Quill 2.3.2
  • 播放2.6.6
  • Postgres JDBC驱动程序42.2.1
  • PostgreSQL 10.2

更新: 向root用户添加了密码"root",并切换为使用与查询文档,因此现在appliation.conf看起来像这样:

UPDATE: Added a password of "root" to the root user and switched to using the same format as the Quill docs, so now appliation.conf looks like this:

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
}

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

But the error message is still basically the same:

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.我猜因为引用的缘故,第一次迭代没有用.

Basically, localhost instead of host. I'm guessing the first iteration didn't work because of the quotes.

这篇关于无法使用Play-2.6和Quill.io加载配置的数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆