Service returning null when calling from model. | Community
Skip to main content
New Participant
November 28, 2023
Solved

Service returning null when calling from model.

  • November 28, 2023
  • 4 replies
  • 3949 views

Hi,
whenever I tried to call my service, from model class I am getting null. I tried annotating with @3214626.

This is how I created the service @8220494 (immediate = true, service = DashboardService.class), can anyone help me with this.

Thanks.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by fmateen

Hi @harinivr 

In your service class try 

@component (immediate = true, service = {DashboardService.class}, enabled=true)

After building and installing the code package at AEM, browse system/console/configMgr and confirm service is available at console.

In case service is not available probably the service is failing to initialize because of some other error. Check error logs to see if there is any failure related to your DashboardService

4 replies

Sudheer_Sundalam
New Participant
November 29, 2023

@harinivr ,

 

As other pointed out, @reference is only used in Sling Servlets, OSGI Services and Schedulers.

Use @OSGiService annotation to inject your custom OSGI Service into Sling Model.

Make sure your OSGI Service is up and running by visting /system/console/component in the OSGI console.

DPrakashRaj
New Participant
November 28, 2023

How your sling model are adapted is it via Resource or slingHttpServletRequest ?

Try with @586265 if you’re sling models are adaptable via Resource.class

fmateen
fmateenAccepted solution
New Participant
November 28, 2023

Hi @harinivr 

In your service class try 

@component (immediate = true, service = {DashboardService.class}, enabled=true)

After building and installing the code package at AEM, browse system/console/configMgr and confirm service is available at console.

In case service is not available probably the service is failing to initialize because of some other error. Check error logs to see if there is any failure related to your DashboardService

Hemant_arora
New Participant
November 28, 2023

try using @OSGIService in sling model

@OSGiService
MyServiceClass myService