Question

I am new in the world of EJB 3.1 and trying to get some basics with the JBoss Application Server 7.1.

At the moment I am stuck at a - really basic - problem. When a bean on the server wants to use another bean I need to use the InitialContext.lookup() method. If I look in the literature I found calls like:

TheBean = (<Interface>) new InitialContext().lookup("<NameOfTheBean>/local");

But this call doesn’t work for me. Every time I get an error like this:

javax.ejb.EJBException: javax.naming.NameNotFoundException

After hours of looking for a solution I found code examples which use another call, something like this:

TheBean = (<Interface>) new InitialContext().lookup("ejb:/<Package>//<NameOfTheBean>!<Package>.<Interface>");

Well this solution works for me but the question is why? Does somebody know why the first call produces exceptions while the second one works fine?

Thanks a lot!

Was it helpful?

Solution

Why? Different versions of JBoss deploys beans with differently default names in JNDI namespace.

  ctx.lookup("BeanName/local")

was right for the JBoss 4.x.x and higher but not for JBoss v7. You can see in you server.log of JB7 how your beans mapped to JNDI names, for example (see java:/jboss/exported/... and how it correspond to your second successive call):

13:57:05,550 INFO               [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC      service thread 1-4) JNDI bindings for session bean named ProductionHistoryBean in deployment unit deployment "navi-ejb3.jar" are as follows:

        java:global/navi-ejb3/ProductionHistoryBean!navi.ejb3.production.history

.ProductionHistoryRemote

        java:app/navi-ejb3/ProductionHistoryBean!navi.ejb3.production.history.Pr

oductionHistoryRemote

        java:module/ProductionHistoryBean!navi.ejb3.production.history.Productio

nHistoryRemote

        java:jboss/exported/navi-ejb3/ProductionHistoryBean!navi.ejb3.production

.history.ProductionHistoryRemote

        java:global/navi-ejb3/ProductionHistoryBean

        java:app/navi-ejb3/ProductionHistoryBean

        java:module/ProductionHistoryBean
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top