How Sling Resource Resolution is done in AEM

The focus of this tutorial is to learn how Apache Sling Resource Resolution is done in AEM.Ā AEM uses Sling to develop web applications over Java content repository. Apache Sling is a Web framework for development of content-oriented applications.

In this tutorial, I have tried to provide very easy , detailed and step by step explanation of how sling resource resolution is done in AEM. After completing this tutorials you will have clear understanding of :-

URL Decomposition

Consider belowĀ URL’s :

Dummy URLā€“

Actual URLĀ http://localhost:4502/cf#/content/aemTutorials/sightlyPage.test.html?x=12

LetsĀ break it down the url into its composite parts:

protocolhostcontent pathselector(s)extensionĀ suffixĀ param(s)

Sling Resource Resolution – Mapping URL to Respective JCR Node :

How a url is mapped to corresponding jcr node in aem. How Sling resource resolution is done. The completeĀ Sling Resource ResolutionĀ is shown in below diagram.

Sling resource resolution in aem

Step-1:Ā Double click on a page in siteadmin , to open respective page in browser.

Step-2-3-4-5: Ā Analyse the URL /contents/aemTutorials/sightlyPageĀ it is known as content path.

  • The /contentsĀ path refers to the path of content folder in crx de.
  • /aemTutorialsĀ refers to the package under contents folder.
  • /sightlyPageĀ refers to our page that we have created underĀ siteadmin.
  • jcr:content of sightlyPage contains a property sling:ResourceType. Which tells sling where our component is located. As shown in above figure it is at training/components/myComponent , means sling needs to check for myComponent under /apps folder.

Step-6: Analyse selector and extension Ā  test.html

  • Sling appends the selector and extension after the component name i.e myComponent.test.html . If it found this component then it render it else it drops the extension and search again.

Sling Resource Resolution Preference

I have recently received a query that :-

If the component contains .html and .jsp files ,Ā then the first preference goes to html or jsp?

Further enhancing above example, lets add few more Ā files to myComponent component under apps.


  • When we create a component, then aem creates a default rendering script by .jsp extension i.eĀ myComponent.jsp
  • Lets create one more file with name myComponent.html.

Note:- Sling decides rendering of script on the basis of selector + extension .Ā First priority goes to selector, if no selector isĀ availableĀ thenĀ priority goes to extension.

Now if we double click our page http://localhost:4502/cf#/content/sample/testing.html Ā then by defaultĀ myComponent.jsp script will be called because here .html is an extension not selector . Means while resolving the script we see for extension in URL(HTML), in crxde we compare it with node name(myComponent) We can ignore the last part .jsp from node name. Its only relevance is .jsp gets priority over .html(sightly) file.

Between jsp and html first priority goes to jsp as by default a component is linked to jsp at the time of creation.

  • Now we add one more file html.jsp ,Ā now if we double click the page thenĀ html.jspĀ will be rendered as here it receives html as selector.
  • Lets add one more file by nameĀ myComponent.html.jsp,Ā now if we double click the page then myComponent.html.jspĀ will be rendered because here it receives myComponent.html as the selector

So the final priority order will beĀ myComponent.html.jsp–>html.jsp–>myComponent.jsp –>myComponent.html

Lets decompose above analysis in simple point, Below is the priority of resolution in Descending order(Highest to lowest):-

  1. Selector +Extension .jsp –> test.myComponent.html.jsp
  2. Selector.jsp –>Ā test.jsp
  3. Extension.jsp –>html.jsp
  4. Node Name.jsp –>Ā myComponent.jsp
  5. method name.jsp(Based on type of request we make Either GET or POST) –> GET.jsp or POST.jsp

Note:-If no match is found then it will look for sling:resourceSuperType if available on the component, then it goes to parent component and again run above 5 rules for script resolution.

Hope You got a clear idea of How Sling Resolution is done in AEM. If you have any further doubt, Please leave a comment.



Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.