我是新手,我正在使用3.1.1版和playframework 2.4.6。我在文档http://slick.typesafe.com/doc/3.1.1/database.html中遵循了本指南。我得到的错误是
***ProvisionException: Unable to provision, see the following errors:
1) Error injecting constructor, java.lang.RuntimeException: java.lang.ClassNotFoundException:
org.postgresql.ds.PGSimpleDataSource
at controllers.Application.<init>(Application.scala:12)
while locating controllers.Application
for parameter 1 at router.Routes.<init>(Routes.scala:31)
while locating router.Routes
while locating play.api.inject.RoutesProvider
while locating play.api.routing.Router
1 error***
这是我在SBT中首先提出的这个
libraryDependencies ++= Seq(
"com.typesafe.slick" %% "slick" % "3.1.1",
"org.slf4j" % "slf4j-nop" % "1.6.4"
)
然后在我的Application.Conf中我把这个
mydb = {
dataSourceClass = org.postgresql.ds.PGSimpleDataSource
properties = {
databaseName = "mydatabasename"
user = "postgres"
password = "mypassword"
}
numThreads = 10
}
然后终于在我的控制器中我只有连接字符串 包控制器
import javax.sql.DataSource
import org.mindrot.jbcrypt.BCrypt
import play.api._
import play.api.mvc._
import slick.driver.PostgresDriver.api._
import scala.concurrent.ExecutionContext.Implicits.global
class Application extends Controller {
val db = Database.forConfig("mydb")
try {
// ...
} finally db.close()
def index = Action {
Ok("My First Controller")
}
}
正如你所看到的那样,我使用postgres驱动程序代替H2,因为我正在使用postgres,这些凭据是正确的并经过验证。