Need help in understanding Sling Models Annotations like @Model, @Inject, and @PostConstruct | Community
Skip to main content
Level 2
September 6, 2023
Solved

Need help in understanding Sling Models Annotations like @Model, @Inject, and @PostConstruct

  • September 6, 2023
  • 3 replies
  • 861 views

What are use of @Model, @586265, and @PostConstruct annotations in Adobe Experience Manager (AEM)? Help me explain this in details. I'd like to gain a deeper understanding of how these annotations work and their practical applications when creating Sling Models in AEM. Any insights or examples would be greatly appreciated!

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 aanchal-sikka

Hello @aem101 

 

For @Model & @PostConstruct, please refer to the documentation shared by @estebanbustamante 

 

@Inject is rarely used in Sling Models now. There are many alternatives are available which are specific to the needs.

Please refer to AEM Sling Model Injectors Annotations Cheat Sheet Reference Guide - Sourced Code

They have beautifully explained the mappings between old @Inject way to new recommended annotations like 

  1. @ScriptVariable
  2. @ValueMapValue
  3. @ResourcePath
  4. @ChildResource
  5. @RequestAttribute
  6. @OSGiService
  7. @Self
  8. @SlingObject

3 replies

Mahedi_Sabuj
Community Advisor
Community Advisor
September 6, 2023
EstebanBustamante
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
September 6, 2023

Hi

 

In my opinion, there is nothing better than the official source, you can learn and understand about sling models on the official sling site. Also, there is a specific section talking about the Available Injectors with some examples, you can read more here: https://sling.apache.org/documentation/bundles/models.html#available-injectors 

 

Esteban Bustamante
aanchal-sikka
Community Advisor
aanchal-sikkaCommunity AdvisorAccepted solution
Community Advisor
September 6, 2023

Hello @aem101 

 

For @Model & @PostConstruct, please refer to the documentation shared by @estebanbustamante 

 

@Inject is rarely used in Sling Models now. There are many alternatives are available which are specific to the needs.

Please refer to AEM Sling Model Injectors Annotations Cheat Sheet Reference Guide - Sourced Code

They have beautifully explained the mappings between old @Inject way to new recommended annotations like 

  1. @ScriptVariable
  2. @ValueMapValue
  3. @ResourcePath
  4. @ChildResource
  5. @RequestAttribute
  6. @OSGiService
  7. @Self
  8. @SlingObject
Aanchal Sikka