Expand my Community achievements bar.

SOLVED

what is the difference between @AemObject and @SlingObject?

Avatar

Level 5

for people who are new to AEM how would anyone explain what is the difference between @AemObject and @SlingObject?

for e.g. : 

public abstract class ComponentModel implements AemComponent {

@SlingObject // AND @AemObject
protected Resource resource;
}

my JUnit code which is like 

ctx.currentResource("/content/location");
locationsModel = ctx.request().adaptTo(LocationsModel.class);

 my JUnit code is working fine if I am using @SlingObject as annotation but not working if @AemObject is being used

please explain me the working of both

Thank you

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

AEM Object: Injects common AEM objects that can be derived from a SlingHttpServletRequest. The injection is class-based, but may be supported by name hints when multiple targets are available for the same class.

 

Sling Object: Injects common Sling objects that can be derived from either a SlingHttpServletRequest, a ResourceResolver or a Resource. The injection is class-based.

 

For detailed description & differences, please go through :

 

https://wcm.io/sling/models/apidocs/io/wcm/sling/models/annotations/AemObject.html 

https://sling.apache.org/apidocs/sling8/org/apache/sling/models/annotations/injectorspecific/SlingOb... 

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

AEM Object: Injects common AEM objects that can be derived from a SlingHttpServletRequest. The injection is class-based, but may be supported by name hints when multiple targets are available for the same class.

 

Sling Object: Injects common Sling objects that can be derived from either a SlingHttpServletRequest, a ResourceResolver or a Resource. The injection is class-based.

 

For detailed description & differences, please go through :

 

https://wcm.io/sling/models/apidocs/io/wcm/sling/models/annotations/AemObject.html 

https://sling.apache.org/apidocs/sling8/org/apache/sling/models/annotations/injectorspecific/SlingOb...