playframework 2.4基本的ebean配置

时间:2015-11-12 17:46:58

标签: playframework-2.4

我正在尝试将播放项目从2.3转换为2.4,并设法按照迁移指南进行编译。

但是我不知道如何获得一个基本的工作mysql数据库连接。 在运行时,它为我提供了堆栈跟踪页面,如下面粘贴的输出。

build.sbt

lazy val root = (project in file(".")).enablePlugins(PlayJava, PlayEbean)
...
"org.the" % "model-dal" % "1.2.3-SNAPSHOT",

application.conf

play.evolutions.enabled=false
ebean.thedb=["models.theapp.*"]

创建了一个ebean.properties文件:

datasource.thedb.username=user
datasource.thedb.password=password
datasource.thedb.databaseUrl=jdbc:mysql://127.0.0.1:3306/thedb
datasource.thedb.databaseDriver=com.mysql.jdbc.Driver

plugins.sbt条目

addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "2.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-play-enhancer" % "1.1.0")

堆栈跟踪

    ! @6o56g5bnj - Internal server error, for (GET) [/] ->

    play.api.UnexpectedException: Unexpected exception[CreationException: Unable to create injector, see the following errors:

    1) Error in custom provider, Configuration error: Configuration error[null]
      while locating play.db.ebean.DefaultEbeanConfig$EbeanConfigParser
      at play.db.ebean.EbeanModule.bindings(EbeanModule.java:24):
    Binding(interface play.db.ebean.EbeanConfig to ProviderConstructionTarget(class play.db.ebean.DefaultEbeanConfig$EbeanConfigParser) eagerly) (via modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon$1)
      while locating play.db.ebean.EbeanConfig
        for parameter 0 at play.db.ebean.EbeanDynamicEvolutions.<init>(EbeanDynamicEvolutions.java:36)
      at play.db.ebean.EbeanDynamicEvolutions.class(EbeanDynamicEvolutions.java:33)
      while locating play.db.ebean.EbeanDynamicEvolutions
      at play.db.ebean.EbeanModule.bindings(EbeanModule.java:23):
    Binding(class play.api.db.evolutions.DynamicEvolutions to ConstructionTarget(class play.db.ebean.EbeanDynamicEvolutions) eagerly) (via modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon$1)
      while locating play.api.db.evolutions.DynamicEvolutions
      while locating play.api.db.evolutions.ApplicationEvolutionsProvider
      at play.api.db.evolutions.EvolutionsModule.bindings(EvolutionsModule.scala:22):
    Binding(class play.api.db.evolutions.ApplicationEvolutions to ProviderConstructionTarget(class play.api.db.evolutions.ApplicationEvolutionsProvider) eagerly) (via modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon$1)
      while locating play.api.db.evolutions.ApplicationEvolutions
    Caused by: Configuration error: Configuration error[null]
            at play.api.Configuration$.configError(Configuration.scala:178)
            at play.api.Configuration.reportError(Configuration.scala:829)
            at play.Configuration.reportError(Configuration.java:351)
            at play.db.ebean.DefaultEbeanConfig$EbeanConfigParser.parse(DefaultEbeanConfig.java:81)
            at play.db.ebean.DefaultEbeanConfig$EbeanConfigParser.get(DefaultEbeanConfig.java:60)
            at play.db.ebean.DefaultEbeanConfig$EbeanConfigParser.get(DefaultEbeanConfig.java:44)
            at com.google.inject.internal.ProviderInternalFactory.provision(ProviderInternalFactory.java:81)
            at com.google.inject.internal.BoundProviderFactory.provision(BoundProviderFactory.java:72)
            at com.google.inject.internal.ProviderInternalFactory.circularGet(ProviderInternalFactory.java:61)
            at com.google.inject.internal.BoundProviderFactory.get(BoundProviderFactory.java:62)
            at com.google.inject.internal.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:46)
            at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1103)
            at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)
            at com.google.inject.internal.SingletonScope$1.get(SingletonScope.java:145)
            at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:41)
            at com.google.inject.internal.SingleParameterInjector.inject(SingleParameterInjector.java:38)

1 个答案:

答案 0 :(得分:0)

(1) application.conf中需要禁用evolution,否则会出现上述异常。 play.evolutions.enabled =假

(2) play db中需要数据库配置。 application.conf文件中的属性,不需要ebean.properties文件。

application.conf

db.thedb.username=user
db.thedb.password=password
db.thedb.databaseUrl=jdbc:mysql://127.0.0.1/thedb
db.thedb.databaseDriver=com.mysql.jdbc.Driver