简体   繁体   中英

In the OSGi/iPOJO world, how to get a list of instances of classes implementing an interface?

In the JavaEE/CDI world, I know how to have the list of instances of classes implementing a given interface : by using Instance<MyInterface> combined with reflections library.

But in the OSGI/iPOJO world, how to do so ?

I know I get one instance by using @Requires MyInterface anInstance . But how can I have a programmatic access to all those classes ?

Just use the BundleContext :

@Context BundleContext context;

public List<ServiceReference> getInstancesImplementingX() {
    return context.getServiceReferences(X.class);   
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM