Yes I agree with you the notion of injection vs. a lookup could use some
clarification in this thread. The injection is occurring in the web service
as I mentioned with the class level annotation as you pointed out.
FWIW the code, in particular the context lookup, I posted works as I use it
every day :-)
What I left out, as obvious, but perhaps not entirely were the details of
the ejb-local-ref in the web.xml -
<ejb-local-ref>
<ejb-ref-name>foo/MyBean/local</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local>com.MyModel</local>
<ejb-link>MyBean</ejb-link>
</ejb-local-ref>
Using the lookup path java:com/env/MyBean actually leads to
javax.naming.NameNotFoundException: No object bound to name
java:comp/env/MyBean
in this case.
On Mon, Mar 16, 2009 at 2:56 PM, <glassfish_at_javadesktop.org> wrote:
> 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
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>