可能是我在google中搜索不正确,但找不到它。
我看过很多关于如何在springboot中为字段创建自定义注释的教程。谈论创建方面等。更准确地说,他们甚至使用ReflectionUtils.fieldCallback来实现面向方面的编程(据我所知)
但是,我不需要一个方面,不需要执行任何代码。我只想要一个注释,我可以通过获取它的类注释来获得它的价值。
此外,我需要为课程添加注释,而不需要为字段添加注释。几乎所有教程都讨论字段的注释和方面。
这就是我在纯Java中所拥有的:
我的服务:
@Service
@Order(0)
@Tag("m")
public class Changes0m extends Changes {
}
我的标签注释:
@Retention(RetentionPolicy.CLASS)
@Target({ElementType.TYPE})
public @interface Tag {
String value() default "";
}
我想这样访问“ m”值:
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.
}
}
我检查了所有可能想到的类似方法,但是基本上任何getAnnotations
/ getDeclaredAnnotations
都给我带来春天的感觉(Service
和Order
)
我想告诉春天我也需要我的Tag annotation
的地方是什么?