Referencing a specific service implementation inside Sling Model using injector-specific annotation | Community
Skip to main content
October 16, 2015
Solved

Referencing a specific service implementation inside Sling Model using injector-specific annotation

  • October 16, 2015
  • 2 replies
  • 2632 views

Hi,

I have two implementation implementing the same OSGi service interface. I would like to reference a specific implementation inside a Sling Model using the appropriate injector-specific annotation, which is @OSGiService annotation. But how could I reference the specific service implementation?

If I was coding an OSGi component I would use the @Reference annotation and specify the property "target" as described here: https://edivad.wordpress.com/2013/08/11/cq5osgi-reference-a-unique-service-implementation/

Thank you!

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 boser87

I managed to reference a particular service implemention using the filter property of the injector specific annotation @OSGiService:

    @OSGiService(filter="(component.name=com.package.ServiceMockedImpl)")
    private Service service;

2 replies

joerghoh
Adobe Employee
Adobe Employee
October 16, 2015

It is not possible to use SCR within a pojo. But for Sling Models there are possibilities to do it, see [1]. I haven't tried it myself yet, but I guess, it does what you want to do.

Jörg

 

[1] http://sling.apache.org/documentation/bundles/models.html#available-injectors, look for OSGI services.

boser87AuthorAccepted solution
October 16, 2015

I managed to reference a particular service implemention using the filter property of the injector specific annotation @OSGiService:

    @OSGiService(filter="(component.name=com.package.ServiceMockedImpl)")
    private Service service;