I can not import filters in playframework 2.3.0

那年仲夏 提交于 2019-12-08 16:22:42

问题


I use playframework 2.3.0, recently I want to add the CSRFFilter

when I import csrf in global.scala:

import play.filters.csrf._

I get an error for this:

[error] G:\testprojects\app\Global.scala:7: object filters is not a member of package play [error] import play.filters.csrf._

My plugin.sbt is

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

I use Build.scala instead of build.sbt

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

)

回答1:


According to the documentation you have to add the filters dependency to your project:

libraryDependencies += filters

The documentation is for build.sbt but I guess it should work with Build.scala too.




回答2:


Play Framework GzipFilter is working for me,

my build.sbt file

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

finally it will work.... (update command is important) if IDE not detecting play.filters
do the above steps one more time
finally copy paste below code

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};
    }
}




回答3:


In Play 2.4.3, the import is:

import play.filters.cors.CORSActionBuilder

It's no longer called csrf, but cors.



来源:https://stackoverflow.com/questions/24257288/i-can-not-import-filters-in-playframework-2-3-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!