本文介绍了PAX-CDI:如何在不使用CDI的情况下获取对捆绑软件中BeanManager的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在bundle A中有一个bundle A,而threre是一个类MyClass.我们假设pax-cdi + weld处于打开状态.

There is a bundle A and threre is a class MyClass in bundle A. And we suppose that pax-cdi+weld is on.

是否可以在不使用@Inject和其他CDI注释的情况下引用MyClass中捆绑软件A的BeanManager?通过osgi服务?或如何?

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?

推荐答案

您可以查找CdiContainer OSGi服务并调用getBeanManager().

You can look up the CdiContainer OSGi service and invoke getBeanManager().

在Pax CDI的最新版本中,CDI.current().getBeanManager()应该也可以正常工作.

With recent versions of Pax CDI CDI.current().getBeanManager() should work as well.

已经说过,Pax CDI的整个想法是使CDI像在Java EE中一样在OSGi中工作.除非您正在开发CDI扩展,否则访问BeanManager有点设计上的味道.

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.

这篇关于PAX-CDI:如何在不使用CDI的情况下获取对捆绑软件中BeanManager的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 16:33