玩Gzip的框架不起作用

时间:2013-10-03 12:39:20

标签: scala playframework gzip playframework-2.2

如你所知,玩吧! 2.2.0版本中的introduced Gzip encoding 不幸的是,在更新项目和更新游戏后,它不起作用。

[error] ...\app\Global.scala:4: object filters is not a member of package play
[error] import play.filters.gzip.GzipFilter
[error]             ^
[error] ...\app\Global.scala:8: not found: type GzipFilter
[error] object Global extends WithFilters(new GzipFilter) with GlobalSettings {
[error]                                       ^
[error] two errors found
[error] (compile:compile) Compilation failed

即使我创建项目表单控制台play new TEST,它也不起作用。

但是在C:\play-2.2.0\framework\src\play-filters-helpers\src\main\scala\play\filters\gzip我同时拥有Gzip.scalaGzipFilter.scala

我的\app\Global.scala看起来像这样:

import play.api._
import play.api.mvc._
import play.api.mvc.Results._
import play.filters.gzip.GzipFilter
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global

object Global extends WithFilters(new GzipFilter) with GlobalSettings {
    override def onStart(app: Application) {
        Logger.info("Application has started")
    }

    override def onStop(app: Application) {
        Logger.info("Application shutdown")
    }

    override def onError(request: RequestHeader, ex: Throwable) = Future { InternalServerError("{}") }
    override def onBadRequest(request: RequestHeader, error: String) = Future { BadRequest("{}") }
    override def onHandlerNotFound(request: RequestHeader) = Future { NotFound("{}") }
}

我做错了什么?有人做过这个吗?

1 个答案:

答案 0 :(得分:16)

Build.scala 中,只需在应用依赖项中添加“过滤器”

val appDependencies = Seq(
  jdbc, cache, filters, ...
)

或者,如果您使用 build.sbt

进行此操作
libraryDependencies ++= Seq(
  jdbc, cache, filters, ...
)