Play Framework注释顺序

时间:2015-08-10 09:24:24

标签: java playframework annotations

当我调用fooMethod时,我想处理第一类注释(使用First.class - 在我的项目中检查是否记录了用户)然后是方法注释(使用Second.class - 在我的项目中检查是否需要使用访问此特定方法的权限。所以我需要确保首先记录用户)。有没有办法做到这一点?

@With(First.class)
public class Foo{

    @With(Second.class)
    public static void fooMethod(){
    }
}

我也想知道为什么custum action会忽略注释。下面的代码不处理anotation @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

2 个答案:

答案 0 :(得分:1)

在Play 2.4中,似乎有一个选项来自文档here

  

注意:如果您想要将动作合成注释放在上面   控制器类在执行操作之前执行   方法设置play.http.actionComposition.controllerAnnotationsFirst =   在application.conf中为true。但是,请注意,如果您使用第三个   项目中的派对模块可能依赖于某个执行顺序   它的注释。

该说明仅出现在2.4文档中,因此可能在以前的版本中不起作用。

答案 1 :(得分:0)

至少在Java 8中,您在相同类型的注释中有一个订单:Java Annotations Reflection Ordering