Sling Models | Community
Skip to main content
Level 2
January 4, 2024
Solved

Sling Models

  • January 4, 2024
  • 2 replies
  • 743 views

Hi Everyone, 

When I am trying to add one custom component to a page, I get a SlingException error:

Error : 

org.apache.sling.scripting.sightly.SightlyException: org.apache.sling.api.SlingException: Cannot get DefaultSlingScript: org.apache.sling.scripting.sightly.SightlyException: Identifier com.mentor.core.core.models.DemoAnnotations cannot be correctly instantiated by the Use API

 

Have tried different things to fix it, but unable to figure out.

Can anyone provide solution on this error? 

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 Mahesh_Gunaje

Hi @nayangarade 

Have u used the correct adaptables? Resource.class or SlingHttpServletRequest.class or Both?

Whether all the injectors are compulsory?  Or else, use defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL

 

Add logger in your init method (custom method name might be different) having @PostConstruct annotation

Is log displayed in logger file?

2 replies

Mahesh_GunajeAccepted solution
Level 7
January 4, 2024

Hi @nayangarade 

Have u used the correct adaptables? Resource.class or SlingHttpServletRequest.class or Both?

Whether all the injectors are compulsory?  Or else, use defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL

 

Add logger in your init method (custom method name might be different) having @PostConstruct annotation

Is log displayed in logger file?

sarav_prakash
Community Advisor
Community Advisor
January 4, 2024

Can you please paste your modal class also? One of your identifier is wrong. Mostly wrong annotation scope. Like you have @2051256 adaptable, but trying to access higher level context objects. Might need to elevate to @SlingServletReqeust. Difficult to guess without seeing your class. Please share. 

Kamal_Kishor
Community Advisor
Community Advisor
January 4, 2024

@nayangarade : Please share both the component dialog field names and DemoAnnotations code snippet. By looking at that only anyone will be able to tell what could be wrong there.
Also, there could be some more information in the logs about what may be the issue here.