'getActionAnnotation'在扩展控制器的特征中找不到
使用 play-scala 模块时,我编写了一个 Secure 特征,如下所示:
trait Secure extends Controller {
self:Controller =>
@Before
def checkAccess = {
if (!session.contains("username")) {
flash.put("url", if (request.method == "GET") request.url else "/")
Action(Authentication.login)
}
var check = getActionAnnotation(classOf[Check])
if (check != null) {
check(check)
}
check = getControllerInheritedAnnotation(classOf[Check])
if (check != null) {
check(check)
}
}
private def check(check: Check) {
for (role <- check.value()) {
if (!check(role)) {
Forbidden
}
}
}
}
但出现以下编译错误:
文件 /app/controllers/Secure.scala 无法编译。引发的错误是:未找到:值 getActionAnnotation
我该如何更正此问题?
When using play-scala module, I write a Secure trait as the following:
trait Secure extends Controller {
self:Controller =>
@Before
def checkAccess = {
if (!session.contains("username")) {
flash.put("url", if (request.method == "GET") request.url else "/")
Action(Authentication.login)
}
var check = getActionAnnotation(classOf[Check])
if (check != null) {
check(check)
}
check = getControllerInheritedAnnotation(classOf[Check])
if (check != null) {
check(check)
}
}
private def check(check: Check) {
for (role <- check.value()) {
if (!check(role)) {
Forbidden
}
}
}
}
But I get the following compilation error:
The file /app/controllers/Secure.scala could not be compiled. Error raised is : not found: value getActionAnnotation
How can I correct this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
getActionAnnotation() 是在 Java Controller 父类中定义的,而不是在 Scala 版本中定义的(它位于 ScalaController 中,但在 Scala 模块的源代码中被“重命名”,请参阅 scala 模块中的 src/play/mvc/package.scala)。
我担心您要么需要 fork&patch Scala 模块,要么从 Java 源代码 (framework/src/play/mvc/Controller.java) 获取源代码。
getActionAnnotation() is defined in the Java Controller parent class, not in the Scala version (which is in ScalaController but gets "renamed" in the Scala module's source, see src/play/mvc/package.scala in the scala module).
I fear you either need to fork&patch the Scala module, or grab the source from the Java source (framework/src/play/mvc/Controller.java).