-
1. Re: JNDI questions (long)
adrian.brock Aug 28, 2003 6:51 AM (in response to gary_kephart)Too many questions, keep it short and sweet.
> I'm able to get EJBs to run on JBoss, but I don't
> completely understand the whole JNDI thing.
> Specifically, what fields match with what other
> fields in other files. An example at this point would
> help:
>
> My client code:
> InitialContext ic = new InitialContext();
> Object objref = ic.lookup("ejb/my_context/MyEJB");
>
> 1) Sometimes I have to use "java:/comp/env/" and
> sometimes, like above, I don't. Why? When should I
> use one over the other? When _can't_ I use one over
> the other?
>
java:comp/env is the preferred method for components
inside jboss. They are aliases to the real jndi links (the other
type). Each component has its own copy of java:comp/env
The other bindings outside java:/ are available globally.
java:/ is only available in the same vm
> My jboss-web.xml:
> <ejb-ref>
> <ejb-ref-name>ejb/my_context/MyEJB</ejb-ref-name>
> <jndi-name>ejb/my_context/MyEJB</jndi-name>
> </ejb-ref>
>
This says java:comp/env/ejb/my_context/MyEJB (ejb-ref-name)
is mapped to ejb/my_context/MyEJB (the real binding)
> 2) I'm guessing that my code must either match
> ejb-ref-name or jndi-name. Which one?
>
It will work with either.
> 3) ejb-ref-name and jndi-name can be different,
> right? Why would one do that?
>
They are at your discretion.
> 4) I don't have to use java:/comp/env in any of the
> xml files because that's already assumed, right?
>
> My web.xml:
> <ejb-ref>
>
> <ejb-ref-name>ejb/my_context/MyEJB</ejb-ref-name>
> <ejb-ref-type>Entity</ejb-ref-type>
> com.mycompany.MyHome
> com.mycompany.MyEJB
> </ejb-ref>
>
It is the prefix to all ref-names
> Ok, I know that the ejb-ref-name in my web.xml must
> match an ejb-ref-name in the jboss-web.xml file.
>
> 5) Perhaps my code must match a ejb-ref-name in here
> instead of in the jboss-web.xml file?
>
> My ejb-jar.xml:
>
> <ejb-name>MyBean</ejb-name>
> com.mycompany.MyHome
> com.mycompany.MyEJB
> <ejb-class>com.mycompany.MyEJBBean</ejb-class>
> <persistence-type>Bean</persistence-type>
>
> <prim-key-class>com.mycompany.MyPK</prim-key-class>
> False
>
>
No. The jndi-name of the ejb-ref in jbossweb.xml maps
to the jndi-name you used to deploy the ejb specified in
jboss.xml
ejb-link work in the same deployment this maps to
an ejb-name
> 6) Easy one. The home and remote in the ejb-jar.xml
> must match the home and remote in the web.xml,
> right?
>
> My jboss.xml:
>
> <ejb-name>MyBean</ejb-name>
> <jndi-name>ejb/MyEJB</jndi-name>
>
>
Yes, but jboss doesn't use it. I think it will still work
if you get it wrong on the ref-name.
> 7) Easy one. The ejb-name in jboss.xml must match the
> ejb-name in ejb-jar.xml, right?
>
Yes
> 8) What does the jndi-name in the jboss.xml have to
> match? I'm guessing it's the jndi-name in
> jboss-web.xml, right?
>
It is the definition, it is not a ref-name.
> Thanks,
> Gary
Keep it shorter next time.
Regards,
Adrian