There seems to be some confusion here about the difference between "injection" vs. looking
up an EE environment dependency. Java EE 5 annotations (@Resource, @EJB, etc.) are
not processed on POJOs. They are processed on a certain set of managed classes such as
servlets, web service endpoint classes, etc.
The result of processing those annotations is a set of environment dependencies that is combined
with the ones defined in the corresponding web.xml or ejb-jar.xml. At runtime, *any* code,
including POJOs, that is executing within the context of a component environment can do a
"java:comp/env/" relative lookup to retrieve one of the current environment's dependencies.
The code listed here is partially correct. If a web service class defines an EJB
dependency called "MyBean" by declaring @EJB , that dependency can be looked up by a
POJO invoked from the Web Service endpoint class.
However, the corresponding lookup
would be new InitialContext().lookup("java:comp/env/MyBean"). The portion after
java:comp/env/ matches the name() attribute of the @EJB dependency.
[Message sent by forum member 'ksak' (ksak)]
http://forums.java.net/jive/thread.jspa?messageID=337278