2016-11-28 64 views
0

有很多關於同樣的錯誤問題,但這些問題的答案並沒有幫助我。無法連接到數據庫 - 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.*"] 
} 
+0

? – marcospereira

+0

我覺得我用的是最新版本,根據「addSbtPlugin(」 com.typesafe.play「%‘SBT-插件’%‘2.5.10’)」 –

回答

0

這是令人難以置信的,但扔掉了默認配置垃圾後,我已經得到了一切工作!

在這裏工作的純配置:

play.crypto.secret = "changeme" 

play.i18n.langs = [ "en" ] 

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.*"] 
0

我想應該是足夠application.conf這樣的:

db { 
    default.driver=com.mysql.jdbc.Driver 
    default.url="mysql://hiddenuser:[email protected]/typobank?characterEncoding=UTF-8" 
    default.username=hiddenuser 
    default.password=pass 
} 
ebean.default=["models.*"] 

UPDATE: 我試過此修復程序,但在啓動過程中這引發異常: this raise an exception during startup

0

db { 
    db.default... 
} 

計算爲db.db.default,這就是爲什麼沒有檢測到它。這是擺在首位的主要原因。它必須是

db { 
    default.driver=com.mysql.jdbc.Driver 
    default.url="jdbc:mysql://localhost/typobank?characterEncoding=UTF-8" 
    default.username=hiddenuser 
    default.password=pass 
} 
你使用的是哪個遊戲的版本