简体   繁体   中英

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.

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.

However, if you want to do any passing of a your annotation's value into the metaannotation value, that's not possible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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