【问题标题】:Play framework with Gzip not working使用 Gzip 播放框架不起作用
【发布时间】:2013-10-03 12:39:19
【问题描述】:

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

[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("{}") }
}

我做错了什么?有没有人让它工作?

【问题讨论】:

    标签: scala playframework gzip playframework-2.2


    【解决方案1】:

    Build.scala 中,只需将“过滤器”添加到您的应用依赖项中

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

    或者,如果您使用 build.sbt

    libraryDependencies ++= Seq(
      jdbc, cache, filters, ...
    )
    

    【讨论】:

    • 非常感谢。您能解释一下,并告诉您将来如何避免类似的错误吗?
    • 要避免缺少依赖项,您无能为力。但是错误消息XXX is not a member of package YYY 始终是一个很好的指示,表明缺少包(只要 YYY 不是您自己的包)。
    • ... 如果您手动创建了 Play 项目,filters ModuleID(依赖项)存在于 play.Project 中,因此请确保在构建文件中包含 import play.Project._ .
    • 完美。它没有立即显示出来,所以我运行了“play clean”、“play eclipse”,然后在 Eclispe 中刷新了我的项目。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多