在我的方法内部,我想获取一个CDI bean,但是我不想使用@ Inject,因为我不需要将此bean保存在实例级别。我只想获取实例并将其传递给其他方法。
[以前,我使用Spring,但是现在切换到JEE应用程序。在Spring的方法中,我可以简单地写:
MyClass myClass = applicationContext.getBean(MyClass.class)
在JEE应用程序中是否可以执行类似的操作?
我在这里找到答案:How to programmatically inject a Java CDI managed bean into a local variable in a (static) method
需要使用:
javax.enterprise.inject.spi.CDI.current().select(C.class).get()