내 커뮤니티 업적 표시줄을 확대합니다.

Submissions are now open for the 2026 Adobe Experience Maker Awards.

Mark Solution

활동이 없어 이 대화는 잠겼습니다. 새 게시물을 작성해 주세요.

해결됨

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 채택된 해결책 개

Avatar

정확한 답변 작성자:
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... 

원본 게시물의 솔루션 보기

1 답변 개

Avatar

정확한 답변 작성자:
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...