Inherit annotations from abstract class?

后端 未结 3 1053
Happy的楠姐
Happy的楠姐 2020-12-06 09:40

Can I somehow group a set of annotations on an abstract class, and every class that extends this class has automatically assigned these annotations?

At least the fol

3条回答
  •  感情败类
    2020-12-06 10:05

    The answer is: no

    Java annotations are not inherited unless the annotation type has the @Inherited meta-annotation on it: https://docs.oracle.com/javase/7/docs/api/java/lang/annotation/Inherited.html.

    Spring's @Component annotation does not have @Inherited on it, so you will need to put the annotation on each component class. @Service, @Controller and @Repository neither.

提交回复
热议问题