Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 JavaEE/CDI 世界中,我知道如何获得实现给定接口的类的实例列表:通过Instance<MyInterface>结合使用反射库。
Instance<MyInterface>
但是在 OSGI/iPOJO 的世界里,该怎么做呢?
我知道我通过使用@Requires MyInterface anInstance. 但是我怎样才能以编程方式访问所有这些类呢?
@Requires MyInterface anInstance
只需使用BundleContext:
BundleContext
@Context BundleContext context; public List<ServiceReference> getInstancesImplementingX() { return context.getServiceReferences(X.class); }