AEM OSGI Services | Community
Skip to main content
Level 3
May 20, 2022 8:20 AM UTC
Solved

AEM OSGI Services

I have three bundles named Bundle1,Bundle2 & Bundle3. I have two services with the same interface  in bundle 2 & 3 and need to refer this interface in bundle 1. How can that be done?  How do I specify the interface with its versions that needs to be exported and imported respectively in two different bundles?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
WasilZeeAccepted solution
Employee
May 20, 2022 12:43 PM UTC

You may register Services(interface implementations) with different properties(e.g. version) and export them. You may then reference the services with the target attribute. See section "Targeting a service implementation" : https://www.deptagency.com/insight/binding-and-unbinding-osgi-services-in-aem/

 

Thanks,

Wasil

3 replies

RajaShankar
New Participant
May 20, 2022 3:04 PM UTC

Hi @manasi29 

There are multiple ways /options in getting the service we need via interface(binding respective service).Please refer my below blog where i provided all options with sample code.

https://rajashankardigital.blogspot.com/2021/08/control-dependency-injection-in-osgi.html

 

Regards,

Rajashankar.R

Translate
SantoshSai
New Participant
May 20, 2022 3:03 PM UTC

Hi @manasi29 

You need to ensure that the other bundle can reference that OSGI Service

  • The bundles consuming the service need to import the fully qualified name of the service interface.
  • The bundle providing the service needs to export the Java package of the service interface.  

for more information please visit this blog https://www.techinnovia.com/package-import-and-export/ 

Hope that helps you!

Regards,
Santosh

 

Translate
Santosh Sai
WasilZeeAccepted solution
Employee
May 20, 2022 12:43 PM UTC

You may register Services(interface implementations) with different properties(e.g. version) and export them. You may then reference the services with the target attribute. See section "Targeting a service implementation" : https://www.deptagency.com/insight/binding-and-unbinding-osgi-services-in-aem/

 

Thanks,

Wasil

Translate