我无法在play framework 2.3.0中导入过滤器

时间:2014-06-17 06:45:43

标签: scala playframework servlet-filters playframework-2.3

我使用playframework 2.3.0,最近我想添加CSRFFilter

当我在global.scala中导入csrf时:

import play.filters.csrf._

我收到错误:

[error] G:\ testprojects \ app \ Global.scala:7:对象过滤器不是成员    包玩    [error] import play.filters.csrf ._

我的plugin.sbt是

...
// The Play plugin
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.3.0")
...

我使用Build.scala而不是build.sbt

lazy val root  = Project("root", base = file(".")).enablePlugins(PlayScala)
.settings(baseSettings: _*)
.settings(libraryDependencies++=appDependencies)
.settings(
  scalaVersion := "2.11.1",
  version := "1.0"

)

3 个答案:

答案 0 :(得分:9)

根据documentation,您必须将过滤依赖项添加到项目中:

libraryDependencies += filters

该文档适用于build.sbt,但我想它也适用于Build.scala。

答案 1 :(得分:1)

Play Framework GzipFilter 正在为我工​​作,

我的build.sbt文件

name := "GZIP"

version := "1.0-SNAPSHOT"

libraryDependencies ++= Seq(
  javaJdbc,
  javaEbean,
  cache,
  filters
)     

play.Project.playJavaSettings

steps to get play.filters package
1. play
2. update            //important
3. clean
4. eclipse
5. compile
6. run

最后它会起作用....(更新命令很重要)    如果IDE未检测到 play.filters
   再一次做上述步骤
   最后复制粘贴代码

import play.GlobalSettings;
import play.api.mvc.EssentialFilter;
import play.filters.gzip.GzipFilter;

public class Global extends GlobalSettings {
    public <T extends EssentialFilter> Class<T>[] filters() {
        return new Class[]{GzipFilter.class};
    }
}

答案 2 :(得分:1)

在Play 2.4.3中,导入为:

import play.filters.cors.CORSActionBuilder

它不再被称为csrf,而是cors