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. | Community
Skip to main content
JakeCham
New Participant
January 4, 2024
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.

  • January 4, 2024
  • 4 replies
  • 1031 views

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 @3214626.
  • BWait for the service ServiceUserMapper via BundleContext.getServiceReference().
  • C. Create a field of type ServiceUserMapped and annotate it with @3214626 using ReferencePolicy.DYNAMIC.
  • D. Create a field of type ServiceUserMapper and annotate it with @3214626 using ReferencePolicy.STATIC.
  •  
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 JagarlamudiVe

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

4 replies

kautuk_sahni
Employee
January 8, 2024

@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
JagarlamudiVeAccepted solution
New Participant
January 5, 2024

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

Raja_Reddy
New Participant
January 4, 2024

Hi @jakecham 

The correct answer is: C

 

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

Madhur-Madan
New Participant
January 4, 2024