To wit: a nonmanaged class looks up an EJB via JNDI. I can deploy successfully; I can even look up a JNDI reference without an exception, which tells me I have something in JNDI... but the lookup returns null, which tells me the binding couldn't find something. I'm looking up a local reference, and I'm assigning the result of lookup() to an Object, so there shouldn't be a casting issue. The only thing I can think of - having been an EJB user since EJB 1.1 or so - is that it's trying to bind a home interface for the EJB, and since it's EJB3, it doesn't really have one (nor should it.)
Maybe I'm just being clueless, and I should do the easiest thing: instantiate the local EJB as if it were a POJO. But that doesn't seem logical to me. It would work, I think, except it would act like an unmanaged object (which is bad) and plus, it'd be, uh, horribly tight coupling, which is pretty much exactly what I don't want.
So... what am I doing wrong? I'm sure I'm missing something simple; I just can't find what it is.
I'm not positive how JBoss-specific this is, but I've gotten away with
looking up "BeanName/remote" on the InitialContext object from the web
tier.
final Context context = new InitialContext();
final MyBean remote = (MyBean) context.lookup("MyBean/remote");
I guess I could also setup a local jndi mapping for this as well (in
comp/env), but I've not gotten that far yet. I've not really looked at
what Java EE 5 has done to the web tier.
Oops. To be clear, the lookup returns a stub implementing the remote
interface, not an instance of the bean. final MyIfc remote = (MyIfc)
context.lookup("MyBean/remote"); would have probably been clearer.
My understanding of the EJB3 spec is that there is no way to do it from
non-managed code other than falling back to EJB2. Should your non-managed
code be a Java EE application client? If so, then you might get some
facilities to get to it but I'm not sure that ever got worked out in the
spec writing.
What is Spring EJB3 support doing for lookup? I'd look there...yes, I'm
being lazy.
Guys, thanks for the replies. However...
BTW, solved it through a search on the glassfish mailing list: see
https://glassfish.dev.java.net/servlets/ReadMsg?list=users&msgNo=605