users@glassfish.java.net

Re: EJB Naming/JNDI Hell Rant

From: <glassfish_at_javadesktop.org>
Date: Mon, 19 May 2008 14:24:07 PDT

This is all very interesting. However, while I've been at this enough to understand everything you're saying, I think I'm personally still lost, and have a similar problem which I cannot resolve.

Currently, I've had great success injecting EJBs into my Servlets, etc. However, I would like to look up a bean, using a dynamically generated name. Injection obviously can't work in such cases, so InitialContext or EJBContext are my options. From this discussion, I'm being led to believe that you can only perform lookups using InitialContext if you already declared a dependency in the .war (above MyServlet, in your example). Injection, being the easier but equivalent route, would save you the trouble.

What if you desire to lookup a bean which isn't known until runtime?

...
InitialContext ic = new InitialContext();
MyBean bean = (MyBean) ic.lookup(string1 + string2); // dynamic remote bean name
...

or better yet

...
@Resource
private SessionContext context;

...
MyBean bean = (MyBean) context.lookup(string1 + string2); // dynamic local bean name
...

Assuming every other form of EJB access works in my current environment (@EJB and @Resource injection, etc.), the above example still remains impossible, correct?
[Message sent by forum member 'sjohnr' (sjohnr)]

http://forums.java.net/jive/thread.jspa?messageID=275347