I am reading up on Java EE CDI and I am a confused about how class-based Resource injection works
The Java EE 6 tutorial gives the following example usage:
@Resource(name="myMessageQueue",
type="javax.jms.ConnectionFactory")
public class SomeMessageBean {
...
}
I get how it is declared but how is the declared resource supposed to be used in the SomeMessageBeanClass
? What is the myMessageQueue
resource injected into?
@Resource
in an annotation that originates from EJB.
Its lineage goes back to the days before injection into fields was possible. In those days, "injection" meant putting something into a kind of map that is associated with each EJB bean; the so-called ENC (Enterprise Naming Context).
You can access this "map" by requesting the "java:/comp" namespace from the InitialContext
when inside an EJB, or directly from the EJB context (which you have to inject as well).
These days using the ENC seems rare. Field injection is much more convenient.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With