【问题标题】:How can i change the execution order of annotations in Spring?如何更改 Spring 中注释的执行顺序?
【发布时间】:2017-09-19 06:33:02
【问题描述】:

我有一个自定义注释@MyAnnotation

@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD })
public @interface MyAnnotation {
  String [] roles() default {};
}

我正在使用我的注释作为

@MyAnnotation
@RequestMapping(value = "/test/xyz", method = RequestMethod.POST)
@ResponseBody
public String myFunc(@Valid TestClass test) {
    return "Name: " + test.getName();
}

我想在 Javax 的 @Valid 注释之前执行我的自定义注释 @MyAnnotation,因为我正在我的注释实现中执行一些安全检查,并且需要在验证正文之前执行这些检查。

有没有一种方法可以提高自定义注释的优先级,使其在@Valid 注释之前执行?

【问题讨论】:

    标签: spring aop spring-annotations


    【解决方案1】:

    【讨论】:

    • 当您将注释都作为自定义注释并且您为注释提供排序时,此方法有效。但是这里的问题是我如何覆盖优先级,以便我的自定义注释在 javax @valid 注释之前执行?基本上我想在验证之前进行预授权。
    • 你有没有解决过@SalmanKhan?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-13
    • 2017-11-24
    相关资源
    最近更新 更多