How to programmatically inject a Java CDI managed bean into a local variable in a (static) method

XDR picture XDR · Jul 17, 2014 · Viewed 28.5k times · Source

How can I programmatically inject a Java CDI 1.1+ managed bean into a local variable in a static method?

Answer

XDR picture XDR · Jul 20, 2014

To inject an instance of class C:

javax.enterprise.inject.spi.CDI.current().select(C.class).get()

This is available in CDI 1.1+