내 커뮤니티 업적 표시줄을 확대합니다.

Submissions are now open for the 2026 Adobe Experience Maker Awards.

Mark Solution

활동이 없어 이 대화는 잠겼습니다. 새 게시물을 작성해 주세요.

해결됨

AEM 6.5 - References in service class are null when extended

Avatar

Level 1

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
    }
}

 

1 채택된 해결책 개

Avatar

정확한 답변 작성자:
Employee Advisor

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

원본 게시물의 솔루션 보기

3 답변 개

Avatar

Level 10

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.

Avatar

정확한 답변 작성자:
Employee Advisor

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

Avatar

Level 4

Hi @Raghul87 ,

I feel you need to inject BaseClass in your ExtendedClass. Inheritance might not work in services I guess.

Thanks!