Expand my Community achievements bar.

SOLVED

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

Avatar

Level 2

What are use of @Model, @inject, 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!

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

View solution in original post

3 Replies

Avatar

Community Advisor

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

Avatar

Correct answer by
Community Advisor

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