It might be I am not searching correctly in google, but I am not able to find it.
I have seen a lot of tutorials on how to create custom annotations for fields in springboot. Talking about creating aspects etc. More precisely, they even use ReflectionUtils.fieldCallback in order to achieve the aspect oriented programming (as far as I've understood)
However, I do not want an aspect, I do not need any code to be executed. I just want an annotation which I can get it's value by getting it's class annotations.
Moreover, I need an annotation for the class not for a field. Almost all tutorials talk about annotations and aspects for fields.
This is what I have, in pure java:
My Service:
@Service
@Order(0)
@Tag("m")
public class Changes0m extends Changes {
}
My Tag annotation:
@Retention(RetentionPolicy.CLASS)
@Target({ElementType.TYPE})
public @interface Tag {
String value() default "";
}
And I want to access that "m" value like this:
public abstract class Changes {
...
protected String getTag() {
return this.getClass().getDeclaredAnnotation(Tag.class).value(); // this.getClass() in runtime gives me the Changes0m.class
//return AnnotationUtils.findAnnotation(this.getClass(), Tag.class).value(); // I tried with AnnotationUtils, did not work.
}
}
I checked all similar methods I could think of, but basically any getAnnotations
/ getDeclaredAnnotations
only gives me spring ones (Service
and Order
)
What I am missing to tell spring that I also need myTag annotation
?