强制派生类将自己声明为 Spring bean



我如何控制,所有派生自某个类的类都必须声明为@Component(这意味着作为春豆)?Spring 是否提供了一种通过父类来控制它的机制?

Workarround:如果父类的子类没有@Component注释,您可以使用 [AspectJ 声明警告][1](或错误)。

(我不是AspectJ专家,所以我不能给你写所需的AJP声明。但是几年前我做过类似的事情,所以我很确定这种方法有效。

粗略的草图,可能包含一些语法错误:

pointcut requiresComponentAnnotation(): yourParentClass+ 
         && !get(@Component)
declare warning : requiresComponentAnnotation() : 
        "expect: @Type(type = "org.springframework.stereotyp.Component")";

相关内容

最新更新