我可以以某种方式在抽象类上对一组注释进行分组,并且扩展该类的每个类都已自动分配了这些注释?
至少以下情况不起作用:
@Service @Scope(value = BeanDefinition.SCOPE_PROTOTYPE) class AbstractService class PersonService extends AbstractService { @Autowired //will not work due to missing qualifier annotation private PersonDao dao; }
答案是 不
除非注释类型具有@Inherited元注释,否则Java注释不会继承:https : //docs.oracle.com/javase/7/docs/api/java/lang/annotation/Inherited.html。
Spring的@Component注释上没有@Inherited,因此你需要将注释放在每个组件类上。@ Service,@ Controller和@Repository都没有。
@Inherited