Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Sling models: the story behind @Inject | AEM Community Blog Seeding




Sling models: the story behind @Inject by Reyn van de Craats


This blog post is based on an issue encountered on a project I’ve worked on. I’ve been working with AEM for a while and in that time I wrote my share of Sling models and unit tests for them. Reading through lots of references on the internet explaining which annotations you can use and how they work. Also using some third-party custom annotations and even adding a custom annotation myself to be used in Sling models.

Yet all this time, the way Sling models work their magic stayed magical somehow... Especially the mysterious @Inject annotation. However, I never encountered really weird behaviour that couldn’t be accounted for one way or another. Until recently.
Before presenting the issue I want to indicate what DOES work.

In an OOTB AEM instance, the Sling model based on the SlingHttpServletRequest works and injects the current page fine, however, the one based on the Resource does not work!
This makes a lot of sense since the current page is present on the request in the sling bindings which can be obtained from the attributes. However, the resource doesn’t keep a reference to the current page nor request. Note: the current page is different from the containing page. It is possible to get the containing page for a resource.

Read Full Blog

Sling models: the story behind @Inject


Please use this thread to ask the related questions.


Topics help categorize Community content and increase your ability to discover relevant content.

0 Replies