Play 框架 2.5 的 Ebean 和 H2 配置问题

Ebean and H2 configuration issue with Play framework 2.5

我正在尝试使用 Play Framework 2.5 版进行开发,但无法正确连接数据库。我正在使用带有 Ebean 插件 3.0.2 的 H2 数据库作为 ORM。根据在 Play Framework 网站上找到的信息和您的许多帖子,我为 application.conf 中的条目尝试了几个选项。请在下面找到我的配置文件条目和错误跟踪并帮助我:

      **Application.conf**

      play.db {
      # The combination of these two settings results in "db.default" as the
      #default JDBC pool:
      config = "db"
      default = "default"
      prototype {
           # Sets a fixed JDBC connection pool size of 50
           #hikaricp.minimumIdle = 50
           #hikaricp.maximumPoolSize = 50

                }
      }

   db { 
     default.hikaricp.dataSourceClassName = org.h2.jdbcx.JdbcDataSource
     default.driver = org.h2.Driver
     default.url = "jdbc:h2:mem:play"
     default.username = sa
     default.password = ""
     ebean.default = ["models.*"] 
     #play.ebean.default.dataSource = default

      default.logSql=true
     }
     **Plugins.sbt**

    addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.5.10")

   // Web plugins
   addSbtPlugin("com.typesafe.sbt" % "sbt-coffeescript" % "1.0.0")
   addSbtPlugin("com.typesafe.sbt" % "sbt-less" % "1.1.0")
   addSbtPlugin("com.typesafe.sbt" % "sbt-jshint" % "1.0.4")
   addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.8")
   addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.1.1")
   addSbtPlugin("com.typesafe.sbt" % "sbt-mocha" % "1.1.0")


    addSbtPlugin("org.irundaia.sbt" % "sbt-sassify" % "1.4.6")
   addSbtPlugin("com.typesafe.sbt" % "sbt-play-enhancer" % "1.1.0")
   enablePlugins(PlayEbean).
   addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "3.0.2")
   addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % 

  "5.0.1")

  **Build.sbt**




   name := """Institut"""

     version := "1.0-SNAPSHOT"

     lazy val Institut = (project in 
     file(".")).enablePlugins(PlayJava,PlayEbean)

     scalaVersion := "2.11.7"

      libraryDependencies ++= Seq(
      javaJdbc,
      cache,
      javaWs,
      evolutions

     )



  **Console output**



   [info] application - Creating Pool for datasource 'ebean'
   [error] c.z.h.HikariConfig - HikariPool-1 - dataSource or
   dataSourceClassName
   or jdbcUrl is required.
   [info] application - Creating Pool for datasource 'ebean'
   [error] c.z.h.HikariConfig - HikariPool-2 - dataSource or 
   dataSourceClassName
   or jdbcUrl is required.
   [info] application - Creating Pool for datasource 'ebean'
   [error] c.z.h.HikariConfig - HikariPool-3 - dataSource or 
   dataSourceClassName
   or jdbcUrl is required.
   [info] application - Creating Pool for datasource 'ebean'
   [error] c.z.h.HikariConfig - HikariPool-4 - dataSource or 
   dataSourceClassName
   or jdbcUrl is required.
   [error] application - 

   ! @736eodoo7 - Internal server error, for (GET) [/] ->

    play.api.Configuration$$anon: Configuration error[Cannot connect to
    database [ebean]]
    at play.api.Configuration$.configError(Configuration.scala:154)
    at play.api.Configuration.reportError(Configuration.scala:806)
    at 
    play.api.db.DefaultDBApi$$anonfun$connect.apply(DefaultDBApi.scala:48)
    at playi.db.DefaultDBApi$$anonfun$connect.apply(DefaultDBApi.scala:42)
    at scala.collection.immutable.List.foreach(List.scala:381)
    at play.api.db.DefaultDBApi.connect(DefaultDBApi.scala:42)
    at play.api.db.DBApiProvider.get$lzycompute(DBModule.scala:72)
    at play.api.db.DBApiProvider.get(DBModule.scala:62)
    at play.api.db.DBApiProvider.get(DBModule.scala:58)
    at            
    Caused by: play.api.Configuration$$anon: Configuration
    error[dataSource or
    dataSourceClassName or jdbcUrl is required.]
    at play.api.Configuration$.configError(Configuration.scala:154)
    at play.api.PlayConfig.reportError(Configuration.scala:996)
    at play.api.db.HikariCPConnectionPool.create(HikariCPModule.scala:70)
    at play.api.db.PooledDatabase.createDataSource(Databases.scala:199)
    at 
    play.api.db.DefaultDatabase.dataSource$lzycompute(Databases.scala:123)
    at play.api.db.DefaultDatabase.dataSource(Databases.scala:121)
    at play.api.db.DefaultDatabase.getConnection(Databases.scala:142)
    at play.api.db.DefaultDatabase.getConnection(Databases.scala:138)
    at 
    play.api.db.DefaultDBApi$$anonfun$connect.apply(DefaultDBApi.scala:44)
    at
    play.api.db.DefaultDBApi$$anonfun$connect.apply(DefaultDBApi.scala:42)
    Caused by: java.lang.IllegalArgumentException: dataSource or 
    dataSourceClassName or jdbcUrl is required.
    at com.zaxxer.hikari.HikariConfig.validate(HikariConfig.java:786)
    at play.api.db.HikariCPConfig.toHikariConfig(HikariCPModule.scala:141)
    at              

    at scala.util.Try$.apply(Try.scala:192)
    at play.api.db.HikariCPConnectionPool.create(HikariCPModule.scala:54)
    at play.api.db.PooledDatabase.createDataSource(Databases.scala:199)
    at 
    play.api.db.DefaultDatabase.dataSource$lazycompute(Databases.scala:123)
    at play.api.db.DefaultDatabase.dataSource(Databases.scala:121)
    at play.api.db.DefaultDatabase.getConnection(Databases.scala:142)

我在 H2 配置中遇到了相同的错误消息,通过添加 dataSourceClassName 解决了这个问题,但是我尝试使用默认值作为 Ebean 的数据源,但没有成功。 谢谢!

ebean.default = ["models.*"] 不是键 db.default 的成员,您必须将它放在 db 之外。

根据你的日志ebean认为这个key是另一个数据库

play.api.Configuration$$anon: Configuration error[Cannot connect to
    database [ebean]]

更多信息在这里:

https://www.playframework.com/documentation/2.5.x/JavaDatabase#H2-database-engine-connection-properties