org.apache.sling.api.SlingException: Cannot get DefaultSlingScript: Identifier com.torrid.aem.dynamicmedia.core.models.ReviewDashboardPageModel cannot be correctly instantiated by the Use API | Community
Skip to main content
New Participant
March 22, 2023
Solved

org.apache.sling.api.SlingException: Cannot get DefaultSlingScript: Identifier com.torrid.aem.dynamicmedia.core.models.ReviewDashboardPageModel cannot be correctly instantiated by the Use API

  • March 22, 2023
  • 2 replies
  • 1320 views

Whenever I try to add '@Reference' of a service in other java file getting the above error.

If I remove the reference then everything works fine.

ERROR:

org.apache.sling.api.SlingException: Cannot get DefaultSlingScript: Identifier com.torrid.aem.dynamicmedia.core.models.ReviewDashboardPageModel cannot be correctly instantiated by the Use API
at org.apache.sling.scripting.core.impl.DefaultSlingScript.service(DefaultSlingScript.java:510) [org.apache.sling.scripting.core:2.3.2]
at org.apache.sling.engine.impl.request.RequestData.service(RequestData.java:552) [org.apache.sling.engine:2.7.2]
at org.apache.sling.engine.impl.filter.SlingComponentFilterChain.render(SlingComponentFilterChain.java:44) [org.apache.sling.engine:2.7.2]
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:82) [org.apache.sling.engine:2.7.2]
at com.day.cq.wcm.core.impl.WCMDeveloperModeFilter.doFilterWithErrorHandling(WCMDeveloperModeFilter.java:164) [com.day.cq.wcm.cq-wcm-core:5.12.158]
at com.day.cq.wcm.core.impl.WCMDeveloperModeFilter.doFilter(WCMDeveloperModeFilter.java:135) [com.day.cq.wcm.cq-wcm-core:5.12.158]
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:72) [org.apache.sling.engine:2.7.2]
at com.day.cq.wcm.core.impl.WCMDebugFilter.doFilterWithErrorHandling(WCMDebugFilter.java:192) [com.day.cq.wcm.cq-wcm-core:5.12.158]
at com.day.cq.wcm.core.impl.WCMDebugFilter.doFilter(WCMDebugFilter.java:159) [com.day.cq.wcm.cq-wcm-core:5.12.158]
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:72) [org.apache.sling.engine:2.7.2]
at com.adobe.acs.commons.granite.ui.components.impl.include.IncludeDecoratorFilterImpl.doFilter(IncludeDecoratorFilterImpl.java:92)

 

Appreciate any help regarding the issue.

 

Thanks,

Nandan

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 nitesh_kumar-1

Hi @nandango1 ,

 

Looks like you are trying to inject an OSGi service into the sling model.

You need to use @OSGiService annotation instead of @Reference.

 

Check the documentation here:-

https://sling.apache.org/documentation/bundles/models.html 

https://sling.apache.org/apidocs/sling8/org/apache/sling/models/annotations/injectorspecific/OSGiService.html 

 

Also, check if the service you are trying to inject is available on the console.

 

Hope this helps!

 

Regards,

Nitesh

2 replies

NandanGo1Author
New Participant
March 22, 2023

The issue is resolved,

I was referencing Service1 which has reference of Service2 in Service2 itself, which some how got in loop.

 

Thank you,

Nandan 

nitesh_kumar-1
nitesh_kumar-1Accepted solution
Employee
March 22, 2023

Hi @nandango1 ,

 

Looks like you are trying to inject an OSGi service into the sling model.

You need to use @OSGiService annotation instead of @Reference.

 

Check the documentation here:-

https://sling.apache.org/documentation/bundles/models.html 

https://sling.apache.org/apidocs/sling8/org/apache/sling/models/annotations/injectorspecific/OSGiService.html 

 

Also, check if the service you are trying to inject is available on the console.

 

Hope this helps!

 

Regards,

Nitesh