Play Framework 注解顺序
Play Framework annotation order
当我调用 fooMethod 时,我想先处理 class 注释(使用 First.class - 在我的项目中,这会检查用户是否已登录),然后处理方法注释(使用 Second.class - 在我的项目中,这会检查用户是否具有访问此特定方法的所需权限。所以我需要确保用户先登录)。有办法吗?
@With(First.class)
public class Foo{
@With(Second.class)
public static void fooMethod(){
}
}
我还想知道为什么自定义操作会忽略注释。下面的代码不处理注解 @With(First.class).
public class Foo2 extends Action<CustomAnnotation> {
@Override
@With(First.class)
public Promise<Result> call(Http.Context context) throws Throwable {
return delegate.call(context);
}
}
}
类似的未回答问题:Java + Play Framework 2 with nested action compositions in the same class
看起来至少在 Java 8 你有一个同类注释的顺序:.
在 Play 2.4 中,文档中似乎有一个选项 here:
Note: If you want the action composition annotation(s) put on a
Controller class to be executed before the one(s) put on action
methods set play.http.actionComposition.controllerAnnotationsFirst =
true in application.conf. However, be aware that if you use a third
party module in your project it may rely on a certain execution order
of its annotations.
该说明仅出现在 2.4 文档中,因此可能在以前的版本中不起作用。
当我调用 fooMethod 时,我想先处理 class 注释(使用 First.class - 在我的项目中,这会检查用户是否已登录),然后处理方法注释(使用 Second.class - 在我的项目中,这会检查用户是否具有访问此特定方法的所需权限。所以我需要确保用户先登录)。有办法吗?
@With(First.class)
public class Foo{
@With(Second.class)
public static void fooMethod(){
}
}
我还想知道为什么自定义操作会忽略注释。下面的代码不处理注解 @With(First.class).
public class Foo2 extends Action<CustomAnnotation> {
@Override
@With(First.class)
public Promise<Result> call(Http.Context context) throws Throwable {
return delegate.call(context);
}
}
}
类似的未回答问题:Java + Play Framework 2 with nested action compositions in the same class
看起来至少在 Java 8 你有一个同类注释的顺序:
在 Play 2.4 中,文档中似乎有一个选项 here:
Note: If you want the action composition annotation(s) put on a Controller class to be executed before the one(s) put on action methods set play.http.actionComposition.controllerAnnotationsFirst = true in application.conf. However, be aware that if you use a third party module in your project it may rely on a certain execution order of its annotations.
该说明仅出现在 2.4 文档中,因此可能在以前的版本中不起作用。