组合注解,注解间属性的传递

组合注解间属性赋值,求解答?

案例如下:


import java.lang.annotation.*;

@Target({ElementType.METHOD,ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
public @interface TextAnnotation {

    String value() default "";
}


import java.lang.annotation.*;

@Target({ElementType.METHOD,ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@TextAnnotation
public @interface CombinationAnnotation {

    @AliasFor(annotation = TextAnnotation.class)
    String value() default "";
}

怎么把CombinationAnnotation 注解的value值给到TextAnnotation 的value

如果你使用的是 Spring 的 @AliasFor,那么你可以尝试使用AnnotatedElementUtils#findMergedAnnotationAnnotatedElementUtils#getMergedAnnotation获取 Spring 合成后的 @TextAnnotation 注解。

如果你对这块的知识感兴趣,可以参考我之前写的两篇文章。