有很多關於同樣的錯誤問題,但這些問題的答案並沒有幫助我。無法連接到數據庫 - PlayFramework + Ebean
錯誤是:
[CompletionException: javax.persistence.PersistenceException: The default EbeanServer has not been defined? This is normally set via the ebean.datasource.default property. Otherwise it should be registered programmatically via registerServer()]
由此引發此錯誤的代碼:
public Result newuser() {
Form<UserAuth> userform = formFactory.form(UserAuth.class).bindFromRequest();
if(userform.hasErrors()) {
return landing();
}
userform.get().save();
flash("success", "User " + userform.get().login + " has been added");
return landing();
}
build.sbt:
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayJava, PlayEbean)
scalaVersion := "2.11.7"
libraryDependencies ++= Seq(
javaJdbc,
cache,
javaWs,
evolutions,
"com.adrianhurt" %% "play-bootstrap" % "1.1-P25-B3",
"mysql" % "mysql-connector-java" % "5.1.21"
)
plugins.sbt:
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.5.10")
addSbtPlugin("com.typesafe.sbt" % "sbt-play-enhancer" % "1.1.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "3.0.2")
application.conf:
play.evolutions {
#db.default.enabled = false
}
play.db {
config = "db"
default = "typobank"
prototype {
# Sets a fixed JDBC connection pool size of 50
#hikaricp.minimumIdle = 50
#hikaricp.maximumPoolSize = 50
pool = "default"
driver = com.mysql.jdbc.Driver
user=user
password=pass
url="jdbc:mysql://localhost/typobank"
hikaricp {
#connectionTestQuery = "SELECT 1"
}
}
}
db {
db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://localhost/typobank?characterEncoding=UTF-8"
db.default.username=hiddenuser
db.default.password=pass
ebean.default=["models.*"]
}
? – marcospereira
我覺得我用的是最新版本,根據「addSbtPlugin(」 com.typesafe.play「%‘SBT-插件’%‘2.5.10’)」 –