PAX-CDI: how to get reference to BeanManager in bundle without using CDI

谁都会走 提交于 2019-12-12 01:57:32

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/38871453/pax-cdi-how-to-get-reference-to-beanmanager-in-bundle-without-using-cdi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!