简体   繁体   English

需要帮助创建 Java 注释

[英]Need help creating a Java Annotation

I have a requirement where I have to modify the annotation我有一个必须修改注释的要求

@Qualifier(CONSTANT + "ABC")
DataSource dataSource;

to

@DataSourceQualifier("ABC")
DataSource dataSource;

Here is my Annotation code:这是我的注释代码:

@Retention(RetentionPolicy.RUNTIME)
@Target(value = {ElementType.FIELD})
public @interface DataSourceQualifier {
    String value();
}

Is it even possible to do this?甚至有可能做到这一点吗? I have previously used annotation with AOP but I do not understand how to create this decorator annotation.我以前使用过 AOP 注释,但我不明白如何创建这个装饰器注释。

If there was no value involved, then it would be possible assuming Qualifier annotation is annotated with @Inherited , then you could annotate your DataSourceQualifier with the @Qualifier , then all the places that you annotate with @DataSourceQualifier for the purpose of annotation processing would act as if they had the @Qualifier annotation.如果不涉及任何value ,则可以假设Qualifier注释使用@Inherited进行注释,然后您可以使用@Qualifier注释您的DataSourceQualifier ,然后您使用@DataSourceQualifier注释的所有位置用于注释处理将起作用好像他们有@Qualifier注释。

However, if you want to do any passing of a your annotation's value into the metaannotation value, that's not possible.但是,如果您想将注释的值传递给元注释值,那是不可能的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM