Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
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

Avatar

Level 3

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

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

Hi @nandan123 ,

 

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/OSGiSer... 

 

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

 

Hope this helps!

 

Regards,

Nitesh

View solution in original post

2 Replies

Avatar

Correct answer by
Employee Advisor

Hi @nandan123 ,

 

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/OSGiSer... 

 

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

 

Hope this helps!

 

Regards,

Nitesh

Avatar

Level 3

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