以编程方式将Bean注入CDI上下文? [英] Inject Bean into CDI Context programmatically?

查看:85
本文介绍了以编程方式将Bean注入CDI上下文?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以手动将bean注入CDI上下文?使用JBoss Seam框架,我总是可以执行类似 Contexts.getConversationContext()。set(foo,bar); 的操作,Bean将成为该上下文的一部分。是否可以在Java EE 6 CDI中执行类似的操作?

Is it possible to manually Inject a bean into a CDI context? With the JBoss Seam framework, I could always do something like Contexts.getConversationContext().set("foo", bar); and the Bean would become part of that context. Is it possible to do something like this in Java EE 6 CDI?

推荐答案

在实现不可知的情况下无法执行此操作办法。您必须深入了解实现,找到范围对象,通过BeanManager将它们拉出来并找出如何添加它们。并非所有这些(很可能都不是)都像地图一样容易设置。

There is no way to do this in an implementation agnostic way. You'd have to dig into the implementation, find the scope objects, pull them out via a BeanManager and figure out how to add them. Not all of them (quite possibly none of them) are as easy to set as maps.

这篇关于以编程方式将Bean注入CDI上下文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆