简体   繁体   English

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

[英]EvolutionsComponents in compile-time dependency injection play project

Im trying to understand how to run evolutions using compile-time DI. 我试图了解如何使用编译时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)


}

But I keep getting error Error:(19, 7) class AppComponents needs to be abstract, since method dbApi in trait EvolutionsComponents of type => play.api.db.DBApi is not defined class AppComponents(context: Context) extends BuiltInComponentsFromContext(context) with EhCacheComponents with EvolutionsComponents 但是我一直收到错误错误:(19,7)类AppComponents必须是抽象的,因为未定义类型=> play.api.db.DBApi的特征EvolutionsComponents中的方法dbApi类AppComponents(context:Context)扩展了BuiltInComponentsFromContext(context )与EhCacheComponents和EvolutionsComponents

I'am newbie in Scala. 我是Scala的新手。

dbApi comes from the DBComponents trait, so your AppComponents class needs to also extend DBComponents . dbApi来自DBComponents特性,因此您的AppComponents类还需要扩展DBComponents You'll also need to extend HikariCPComponents for the connection pool. 您还需要为连接池扩展HikariCPComponents

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

Be sure to add the evolutions and jdbc dependencies to your build.sbt file. 确保将evolutionsjdbc依赖项添加到build.sbt文件中。

I needed to extend all of this. 我需要扩展所有这些内容。 More reading Cake Pattern Play documentation 更多阅读Cake Pattern 播放文档

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

and add jdbc suport inside build.sbt 并在build.sbt中添加jdbc suport

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

.... ....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Play 框架编译时依赖注入和单例 - Play framework compile-time dependency injection and singleton Play 2.4 WebSocket在使用编译时依赖项注入时抛出InstantiationException - Play 2.4 WebSocket throws InstantiationException when using compile-time dependency injection 使用Playframework 2.6 Macwire进行设置,使用编译时依赖性注入进行测试 - Setting up, Testing with compile-time Dependency Injection, with Playframework 2.6 Macwire 使用play.api.cache.Cache和编译时依赖注入 - Using play.api.cache.Cache with compile time dependency injection 将现有的Play静态路由与新的“编译时”依赖注入的控制器实例混合 - Mixing existing Play static routes with new 'compile-time' dependency-injected controller instances Scala依赖注入用于单独配置的编译时间 - Scala Dependency Injection for compile time with separate configuration 有没有办法在编译时测试一个常量是编译时常量? - Is there a way to test at compile-time that a constant is a compile-time constant? 播放依赖注入错误 - Play Dependency Injection Error Scala编译时递归? - Scala compile-time recursion? Play 2.5,Scala,编译时DI:使用Java控制器时崩溃,app.requestHandler不是JavaCompatibleHttpRequestHandler - Play 2.5, Scala, compile-time DI: crash when using Java controller, app.requestHandler is not a JavaCompatibleHttpRequestHandler
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM