The @Resource annotation for a service is not injecting a subclass unless I explicitly include the @Component annotation in the subclass. Is there a way to request a subclass be “wired” with the parent @Resource without requiring annotations in each child class? The way I discovered this was by creating a subclass and failing to include the @Component annotation. I was quickly faced with the dreaded NPE.
The @Resource annotation for a service is not injecting a subclass unless I explicitly
Share
@Componentannotation works only for the class where it’s declared, not for its subclasses (for performance reasons, I guess: otherwise it would require traversing of all ancestors for each class being scanned).As a workaround, you can declare an
assignablefilter for your parent class in<context:component-scan>: