Search code examples
scalaquill

Setup everything ok but got error "Failed to load data source for config" while try to use Quill?


I try to use quill in IDEA,setup everything ok:

1 sbt dependencies:

libraryDependencies ++= Seq(
 "mysql" % "mysql-connector-java" % "8.0.17",
 "io.getquill" %% "quill-jdbc" % "3.7.0"
)

2 application.properties(with my params):

ctx.dataSourceClassName=com.mysql.cj.jdbc.MysqlDataSource
ctx.dataSource.url=jdbc:mysql://host/database
ctx.dataSource.user=root
ctx.dataSource.password=root
ctx.dataSource.cachePrepStmts=true
ctx.dataSource.prepStmtCacheSize=250
ctx.dataSource.prepStmtCacheSqlLimit=2048
ctx.connectionTimeout=30000

I have not find where to put file application.properties in sbt project,but I have copy it in every floder:the top floder of the project,floder /src,floder /project,so I think it will work

3 the code(using mysql "world" database):

import io.getquill._

object A extends App{

 lazy val ctx = new MysqlJdbcContext(SnakeCase, "ctx")
 import ctx._

 case class City(id: Int,name:String,countryCode:String,district:String,population:Int)

 val q = quote {
  query[City].filter(c => c.id > 1)
 }

 ctx.run(q) 
}

but got error:

[main] ERROR com.zaxxer.hikari.HikariConfig - HikariPool-1 - dataSource or dataSourceClassName or 
jdbcUrl is required.
Exception in thread "main" java.lang.IllegalStateException: Failed to load data source for config: 
'Config(SimpleConfigObject({}))'
at io.getquill.JdbcContextConfig.dataSource(JdbcContextConfig.scala:25)
at io.getquill.MysqlJdbcContext.<init>(MysqlJdbcContext.scala:14)
at io.getquill.MysqlJdbcContext.<init>(MysqlJdbcContext.scala:15)
at io.getquill.MysqlJdbcContext.<init>(MysqlJdbcContext.scala:16)
at A$.ctx$lzycompute(A.scala:5)
at A$.ctx(A.scala:5)
at A$.delayedEndpoint$A$1(A.scala:14)
at A$delayedInit$body.apply(A.scala:3)
at scala.Function0.apply$mcV$sp(Function0.scala:34)
at scala.Function0.apply$mcV$sp$(Function0.scala:34)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scala.App.$anonfun$main$1$adapted(App.scala:76)
at scala.collection.immutable.List.foreach(List.scala:388)
at scala.App.main(App.scala:76)
at scala.App.main$(App.scala:74)
at A$.main(A.scala:3)
at A.main(A.scala)
Caused by: java.lang.IllegalArgumentException: dataSource or dataSourceClassName or jdbcUrl is required.
at com.zaxxer.hikari.HikariConfig.validate(HikariConfig.java:1004)
at com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:77)
at io.getquill.JdbcContextConfig.dataSource(JdbcContextConfig.scala:22)
... 16 more

so how to fix it?I think this program can't find the config.Thanks!


Solution

  • Put the config properties into your application.conf instead of application.properties