Where is the JNDI name in my code?

I created EJB2.0 using Eclipse 3.7 IDE and deployed to JBoss 5 application server (my bean name is product). I am doing normal context search (and other things to call ejb) and I can successfully call EJB. Now my question is what exactly the JNDI name is exactly, and where was it used in all of this. Is my bean JNDI name or is it my JNDI name -> org.jnp.interfaces.NamingContextFactory

. Where is the JNDI name in this ????? my code: -

// initial code.............
Context  ctx = getContext();
Object obj=ctx.lookup("Product");
ProductHome home =(ProductHome)  javax.rmi.PortableRemoteObject.narrow(obj,ProductHome.class);
ProductRemote remote=home.create();

Product prd = new rohit.Product("PRDCamera",001,50.50) ;
remote.addProduct(prd);
remote.updateProduct(prd);
remote.removeProduct(001);
remote.findProduct(001);
remote.findAllProduct();


// getContext Method

public static InitialContext getContext() throws Exception{
    Properties pro = new Properties();
    pro.put(javax.naming.InitialContext.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
    pro.put(javax.naming.InitialContext.PROVIDER_URL,"localhost:1099");
    return new InitialContext(pro);
}

      

+3


source to share


1 answer


The code is missing the JNDI name.

This is how you look at EJBs in EJB 2.0:

Object ejbHome = initialContext.lookup("java:comp/env/com/mycorp/MyEJB");

MyHome myHome = (MyHome)javax.rmi.PortableRemoteObject.narrow(
  (org.omg.CORBA.Object)ejbHome, MyHome.class);

      

In this case, the name is JNDI java:comp/env/com/mycorp/MyEJB

.



In the much more supportive EJB 3.0, you simply do

MyEJB myEJB = initialContext.lookup("java:comp/env/com/mycorp/MyEJB")

      

and do away with the terrible idea of ​​a home interface.

+3


source







All Articles