问题是组件注释类型本身需要用@Inherited标记.
您的@InheritedComponent注解类型由扩展超类的任何类正确继承,该类被标记为@InheritedComponent,但不会继承@Component.这是因为您在注释上具有@Component,而不是父类型.
一个例子:
public class InheritedAnnotationTest {
@InheritedComponent
public static class BaseComponent {
}
public static class SubClass extends BaseComponent {
}
public static void main(String[] args) {
SubClass s = new SubClass();
for (Annotation a : s.getClass().getAnnotations()) {
System.out.printf("%s has annotation %s\n",s.getClass(),a);
}
}
}
class brown.annotations.InheritedAnnotationTest$SubClass has annotation @brown.annotations.InheritedComponent()
换句话说,当解析类具有什么注释时,注释的注释不会被解析 – 它们不适用于类,只适用于注释(如果有意义).