[英]EvolutionsComponents in compile-time dependency injection play project
我试图了解如何使用编译时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的特征EvolutionsComponents中的方法dbApi类AppComponents(context:Context)扩展了BuiltInComponentsFromContext(context )与EhCacheComponents和EvolutionsComponents
我是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
文件中。
我需要扩展所有这些内容。 更多阅读Cake Pattern 播放文档
class AppComponents(context: Context) extends BuiltInComponentsFromContext(context) with EhCacheComponents with EvolutionsComponents with DBComponents with HikariCPComponents{
并在build.sbt中添加jdbc suport
libraryDependencies ++= Seq(
filters,
evolutions,
jdbc,
cache,
....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.