Am running application in AEM 6.5. I wrote service class with some References and uses SCR annotations. When extending this class and try to call the methods in the parent class the reference are null throwing Null Pointer Exception.
import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Service; @Component @Service public class BaseClass implements IBase { @Reference protected HelperServiceImpl helperServiceImpl; protected void someMethod() { helperServiceImpl.getHelp(); //Here the helperServiceImpl is null when called from the extended class } } import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Service; @Component @Service public class ExtendedClass extends BaseClass implements IExtend { protected void someMethod2() { helperServiceImpl.getHelp(); //Call HelperServiceImpl class reference which is present in parent class } }
Solved! Go to Solution.
Views
Replies
Total Likes
SCR and OSGI Annotations are not inherited.
You can find a good explanation why this isn't the case here: https://github.com/osgi/osgi.enroute.site/blob/pre-R7/_faq/ds-inheritance.md
Hi @Raghul87,
Cross check if HelperServiceImpl is an OSGI service, annotated with @Service. (Per the naming convention, am assuming it to be just a component and not declared as Service)
If it is a service and yet the reference is null, share HelperServiceImpl class if possible to debug further.
SCR and OSGI Annotations are not inherited.
You can find a good explanation why this isn't the case here: https://github.com/osgi/osgi.enroute.site/blob/pre-R7/_faq/ds-inheritance.md