Search code examples
javaosgiaem

Call method of subclass from parent reference


I have 3 OSGi bundles in such as way, implemented class is of same name but in different bundles :

Bundle A (com.adobe) ---- Interface ( foo() )
Bundle B (org.custom) ---- ChildClassA ( foo() {} )
Bundle C (myprj.adobe) ---- ChildClassA ( foo() {} )

I have a snippet as below :

Interface refObj;
refObj.foo();

How can i inject the object of specific implemented class from another bundle.

Thanks,


Solution

  • If you have different services that implement the same interface then you can add properties to the services.

    On the client side you can use a reference with a target.

    @Reference(target="(key=value)")

    This reference will only match a service with a property "key" that has the value "value".