Inherit annotations from abstract class?

后端 未结 3 1064
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:12

    I have this piece of code in my project and it works just fine, although it's not annotated as Service:

    public abstract class AbstractDataAccessService {
    
        @Autowired
        protected GenericDao genericDao;
    
    
    }
    

    and

    @Component
    public class ActorService extends AbstractDataAccessService {
    
        // you can use genericDao here
    
    }
    

    So you don't need to put annotation on your abstract class but even if you do you will still have to put annotation on all subclass as @Component or @Service annotations are not inherited.

提交回复
热议问题