There is a bundle A and threre is a class MyClass in bundle A. And we suppose that pax-cdi+weld is on.
Can can I get reference to BeanManager of the bundle A inside MyClass without using @Inject and other CDI annotations? Via osgi service? Or how?
You can look up the CdiContainer
OSGi service and invoke getBeanManager()
.
With recent versions of Pax CDI CDI.current().getBeanManager()
should work as well.
Having said that, the whole idea of Pax CDI is to make CDI work in OSGi just like in Java EE. Accessing the BeanManager
is a bit of a design smell, unless you are developing a CDI extension.