Expand my Community achievements bar.

SOLVED

Q ) A custom AEM application contains a service component that needs to access the JCR repository within the activate method. The activate method uses ResourceResolverFactory.getServiceResourceResolver("¦) without specifying a sub service name.

Avatar

Level 7

What should be done to make sure the user service mapping for the service component is available?

 

  • ACreate a field of type ServiceUserMapped and annotate it with @reference.
  • BWait for the service ServiceUserMapper via BundleContext.getServiceReference().
  • C. Create a field of type ServiceUserMapped and annotate it with @reference using ReferencePolicy.DYNAMIC.
  • D. Create a field of type ServiceUserMapper and annotate it with @reference using ReferencePolicy.STATIC.
  •  
Topics

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

1 Accepted Solution

Avatar

Correct answer by
Level 4

Hi @JakeCham 

Correct Ans is

D. Create a field of type ServiceUserMapper and annotate it with @reference using ReferencePolicy.STATIC.

 

The ServiceUserMapper service is a core Apache Sling service and will typically be available before any custom services that depend on it. Thus, the OSGi references to this service should be satisfied with a static reference policy. The @Reference annotation with ReferencePolicy.STATIC is used to inject a reference to the necessary service, in this case, ServiceUserMapper. It means that the reference to the ServiceUserMapper OSGi service will be injected when the component is activated.

 

Thanks,

Venkat

View solution in original post

4 Replies

Avatar

Community Advisor

Hi @JakeCham 

The correct answer is: C

 

C. Create a field of type ServiceUserMapped and annotate it with @reference using ReferencePolicy.DYNAMIC.



Avatar

Correct answer by
Level 4

Hi @JakeCham 

Correct Ans is

D. Create a field of type ServiceUserMapper and annotate it with @reference using ReferencePolicy.STATIC.

 

The ServiceUserMapper service is a core Apache Sling service and will typically be available before any custom services that depend on it. Thus, the OSGi references to this service should be satisfied with a static reference policy. The @Reference annotation with ReferencePolicy.STATIC is used to inject a reference to the necessary service, in this case, ServiceUserMapper. It means that the reference to the ServiceUserMapper OSGi service will be injected when the component is activated.

 

Thanks,

Venkat

Avatar

Administrator

@JakeCham Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.



Kautuk Sahni