【发布时间】:2018-04-24 21:53:59
【问题描述】:
我正在尝试使用 PostgreSQL 驱动程序在 Intellij IDEA 中使用 Slick 创建一个项目。但我只找到了this tutorial 我跟着它,但我有一个错误: 线程“主”java.lang.ExceptionInInitializerError 中的异常 在 Main.main(Main.scala) 原因:com.typesafe.config.ConfigException$Missing:未找到密钥“url”的配置设置
这是我的主类代码:
import scala.slick.driver.PostgresDriver.simple._
object Main {
case class Song(
id: Int,
name: String,
singer: String)
class SongsTable(tag: Tag) extends Table[Song](tag, "songs") {
def id = column[Int]("id")
def name = column[String]("name")
def singer = column[String]("singer")
def * = (id, name, singer) <> (Song.tupled, Song.unapply)
}
lazy val songsTable = TableQuery[SongsTable]
val db = Database.forConfig("scalaxdb")
def main(args: Array[String]): Unit = {
val connectionUrl = "jdbc:postgresql://localhost/songs?user=postgres&password=postgresp"
Database.forURL(connectionUrl, driver = "org.postgresql.Driver") withSession {
implicit session =>
val songs = TableQuery[SongsTable]
songs.list foreach { row =>
println("song with id " + row.id + " has name " + row.name + " and a singer is " + row.singer)
}
}
}
}
这些是 application.conf 文件:
scalaxdb = {
dataSourceClass = "slick.jdbc.DatabaseUrlDataSource"
properties = {
driver = "org.postgresql.Driver"
url = "jdbc:postgresql://localhost/dbname?user=user&password=password"
}
}
这是 build.sbt:
libraryDependencies ++= Seq(
"org.postgresql" % "postgresql" % "9.3-1100-jdbc4",
"com.typesafe.slick" %% "slick" % "2.1.0",
"org.slf4j" % "slf4j-nop" % "1.6.4"
)
我无法弄清楚我做错了什么。对于解决此问题的任何建议,我将不胜感激。
【问题讨论】:
标签: postgresql scala intellij-idea slick