Scala 编译时依赖项注入播放项目中的EvolutionsComponents

Scala 编译时依赖项注入播放项目中的EvolutionsComponents,scala,playframework-2.5,playframework-evolutions,Scala,Playframework 2.5,Playframework Evolutions,我试图理解如何使用编译时DI运行演进 import play.api.ApplicationLoader.Context import play.api.cache.EhCacheComponents import play.api.mvc.EssentialFilter import play.api.routing.Router import play.api._ import play.api.db.evolutions.{ DynamicEvolutions, EvolutionsCom

我试图理解如何使用编译时DI运行演进

import play.api.ApplicationLoader.Context
import play.api.cache.EhCacheComponents
import play.api.mvc.EssentialFilter
import play.api.routing.Router
import play.api._
import play.api.db.evolutions.{ DynamicEvolutions, EvolutionsComponents}
import play.filters.gzip.GzipFilter
import router.Routes

class AppLoader extends ApplicationLoader  {
  override def load(context: Context): Application = {
    LoggerConfigurator(context.environment.classLoader).foreach(_.configure(context.environment))
    new AppComponents(context).application
  }


}

class AppComponents(context: Context) extends BuiltInComponentsFromContext(context) with EhCacheComponents with EvolutionsComponents {

  lazy val applicationController = new controllers.Application(defaultCacheApi)
  lazy val usersController = new controllers.Users(defaultCacheApi)
  lazy val assets = new controllers.Assets(httpErrorHandler)

  applicationEvolutions

  // Routes is a generated class
  override def router: Router = new Routes(httpErrorHandler, applicationController, usersController, assets)

  val gzipFilter = new GzipFilter(shouldGzip =
    (request, response) => {
      val contentType = response.header.headers.get("Content-Type")
      contentType.exists(_.startsWith("text/html")) || request.path.endsWith("jsroutes.js")
    })

  override lazy val httpFilters: Seq[EssentialFilter] = Seq(gzipFilter)


}
但我总是出错 错误:(19,7)类AppComponents需要是抽象的,因为类型=>play.api.db.dbApi的trait EvolutionsComponents中的方法dbApi未定义 类AppComponents(context:context)使用EhCacheComponents和EvolutionsComponents扩展了内置组件fromContext(context)


我是Scala的新手

dbApi
来自
DBComponents
特性,因此您的
AppComponents
类也需要扩展
DBComponents
。您还需要为连接池扩展
HikariCPComponents

class AppComponents(context: Context) extends BuiltInComponentsFromContext(context)
  with EhCacheComponents
  with EvolutionsComponents
  with DBComponents
  with HikariCPComponents {

确保将
evolutions
jdbc
依赖项添加到
build.sbt
文件中。

我需要扩展所有这些。更多阅读蛋糕模式

并在build.sbt中添加jdbc支持

libraryDependencies ++= Seq(
 filters,
 evolutions,
 jdbc,
 cache,

..

这起作用了:类AppComponents(上下文:上下文)使用EhCacheComponents(上下文)扩展了内置组件,EhCacheComponents使用Evolutions组件,DBComponents使用HikariCPComponents组件,但是我自己如何获得它呢?例如,这个HikariCPComponents也是需要的?你说的“我自己去拿”是什么意思?你想要什么?另外,您使用什么库进行JDBC访问?滑头?我自己试图扭转对工程师的依赖性来得出这个结论。我在看EvolutionsModule.scala-特质进化组件。但我并不连接EvolutionsComponents和DBComponents(play-jdbc-api_2.11-2.5.6.jar)。再说一遍,我怎么知道我需要包含libraryDependencies(jdbc),它带来了play-jdbc_2.11-2.5.6.jar——在它里面,还有这个HikariCPComponents也需要实现。Cloude我得到了同样的结论,仅仅是看看代码,或者进化文档?在游戏文档中,他们对此只字未提。同意,游戏文档可能会更好。我很高兴你明白了!通常,我处理此类问题的策略是查看开源项目的代码示例。。
libraryDependencies ++= Seq(
 filters,
 evolutions,
 jdbc,
 cache,