简体   繁体   English

CDI:通过静态方法获取对beanManager的引用

[英]CDI: get reference to beanManager via static method

I use weld+paxcdi on java se. 我在java se上使用weld + paxcdi。 I can get the reference to beanManager using 我可以使用获得对beanManager的引用

@Inject
BeanManager beanManager;

However, it's clear that I can use this way only in objects that are managed by CDI container. 但是,很明显,我只能在CDI容器管理的对象中使用这种方式。 How can I get reference to beanmanager in object that was created by new? 我如何在new创建的对象中引用beanmanager?

I assume the question refers to OSGi, as it wouldn't make sense to use Pax CDI otherwise. 我认为这个问题是针对OSGi的,因为否则使用Pax CDI是没有意义的。

Pax CDI creates a separate CDI container and thus a separate bean manager per bean bundle. Pax CDI创建一个单独的CDI容器,从而为每个bean捆绑包创建一个单独的bean管理器。 For this reason, it is not quite obvious what the current bean manager should be. 因此, 当前的 bean管理器应该是什么并不十分明显。

As of Pax CDI 1.0.0.RC1, CDI.current() returns a meaningful value when called from an OsgiServiceProvider method, if the method target is an injection point in the calling class. 从Pax CDI 1.0.0.RC1 CDI.current() ,如果方法目标是调用类中的注入点, OsgiServiceProvider方法调用时, CDI.current()返回有意义的值。 CDI.current() is undefined otherwise. 否则, CDI.current()是未定义的。

Pax CDI 0.x is based on CDI 1.0 and thus does not support CDI.current() . Pax CDI 0.x基于CDI 1.0,因此不支持CDI.current()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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