0
votes

I have written a simple sling component which has one interface and another one is implemented class. I am building this bundle jar using maven,i am installing it from CQ felix console.Bundle is uploaded successfully and it's in active state.

When i am trying to instantiate this bundle class from component jsp ,Null pointer exception is coming this is happening due to not able get the reference of that implemented class.Below is the jsp code snippet using to call this class. Below is the code to instantiate bundle class:

InvokeAEMWorkflowImpl wfService = sling.getService(InvokeAEMWorkflowImpl.class);

And also i have observed one more thing ,i am not able to see anything related to this felix console's component and service areas(tabs).

Can someone help me why i am not able to refer this class in my component jsp.

Thanks, Kishore

1
Please post source code of the InvokeAEMWorkflowImpl (at least the class declaration with SCR annotations) and maven-bundle-plugin configuration from the pom.xml.Tomek Rękawek
This is the implementation class and also included bundle plugin as well...@Component(immediate=true) @Service public class InvokeAEMWorkflowImpl implements InvokeNewWorkflow {//This is not the complete struture}kishore

1 Answers

1
votes

From your comment I assume that you've registered the service as follows:

@Component(immediate=true)
@Service
public class InvokeAEMWorkflowImpl implements InvokeNewWorkflow {
...

According to the SCR Annotation documentation, the @Service annotation registers service using all implemented interfaces (in your case it's InvokeNewWorkflow). Therefore you should use this interface to get the service from the OSGi:

InvokeNewWorkflow wfService = sling.getService(InvokeNewWorkflow.class);

It's a good programming practice to separate interface and implementation, so classes using the interface doesn't need to know anything about the interface.