Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

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

Avatar

Level 4

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!

1 Accepted Solution

Avatar

Correct answer by
Level 4

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;

View solution in original post

2 Replies

Avatar

Employee Advisor

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.

Avatar

Correct answer by
Level 4

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;