java注解执行顺序_如何确保java中的注释执行顺序?
您可以使用@Order注釋確保自定義注釋的順序.
例:
第一個注釋:
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface CustomAnnotation {
}
@Aspect
@Component
@Order(value = 1)
public class CustomAnnotationInterceptor {
@Before("@annotation(customAnnotation )")
public void intercept(JoinPoint method, CustomAnnotation customAnnotation ) {
//Code here
}
}
第二個注釋:
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface CustomAnnotationTwo {
}
@Aspect
@Component
@Order(value = 2)
public class CustomAnnotationInterceptorTwo {
@Before("@annotation(customAnnotationTwo )")
public void intercept(JoinPoint method, CustomAnnotationTwo customAnnotationTwo ) {
//Code here
}
使用它們:
@CustomAnnotationTwo
@CustomAnnotation
public void someMethod(){
}
在此示例中,CustomAnnotationInterceptor將首先執行.
總結
以上是生活随笔為你收集整理的java注解执行顺序_如何确保java中的注释执行顺序?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: datagridview 手动添加的行如
- 下一篇: docker redis重启_Docke