Wednesday, September 13, 2006

JNDI in EJB3

Again (and every time again) after a while without EJB development I had to get used to the way the references to the EJB component interfaces get published in JNDI.

Using JBoss, it is very helpfull to go to http://:8080/jmx-console and having a look at the JNDIView MBean. It will give you a printout of the complete JNDI namespace as available.

I am yet to figure out how to access an integrated (read: in the same application) ejb from a web component. There is hardly anything about this on the web...

A standalone (or separate) client uses the global JNDI space to access objects, thus with EJB3 in JBoss, EJB references are by default being published like so:
<project>/<beanclassname>/<remote|local>


Note that the EJB implementation name is used, not the interface name (kinda logical, though since the interface can be local or remote)

Thus when referencing the bean use for example:

context.lookup("/myProject/myBean/remote")

and don't omit the leading "/"!


Oh, yeah and don't try to inject the EJB reference when you are in a web project: the 2.5 specification for web-apps is needed and it is not done yet! :)
If you want to play around with it anyways, here is the inclusion string:
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"


Have a nice one,
Che

1 comment:

Stephan unterwegs said...

Not sure why, but for ANY weird reason the link: 'http://:8080/jmx-console' does not work on my PC ;))))

Mate ... didn't even know u got another blog :D - call me when u find the time ;)

Ste