使用安全助手不编译:play framework 2.3.x.

时间:2014-12-15 10:02:05

标签: scala playframework-2.3

我正在尝试使用控制器内的安全助手,如Security.scala的源代码所示

https://github.com/playframework/playframework/blob/2.3.x/framework/src/play/src/main/scala/play/api/mvc/Security.scala#L31

我的代码看起来像

import play.mvc.Security.Authenticated

Application extends Controller {
  ..... some other Actions
  def isAuthenticated(f: => String => Request[AnyContent] => Result) = {
      Authenticated { user =>
          Action(request => f(user)(request))
        }
    }
}

但是,我收到以下编译错误

[info] Compiling 1 Scala source to /home/venki/play/lrs/target/scala-2.11/classes...
[error] /home/venki/play/lrs/app/controllers/Application.scala:119: object play.mvc.Security.Authenticated is not a value
[error]       Authenticated { user =>
[error]       ^
[error] one error found
[error] (compile:compile) Compilation failed

我无法理解错误。从源代码中我可以看到Security对象包含两个名为Authenticated的重载方法。我完全复制粘贴了作为示例用法给出的代码,但它仍然无法正常工作。非常感谢任何帮助

1 个答案:

答案 0 :(得分:6)

您在github上引用的安全类型位于play.api.mvc包中,但您要从play.mvc导入该类型。 play.mvc保留用于Java,而不是Scala,see here以获取更多信息。