JNDI question?

Discussions

EJB programming & troubleshooting: JNDI question?

  1. JNDI question? (4 messages)

    I use an servlet calling an Local interface sessionBean,but the Exception tell me Naming not found , I think this reason is JNDI deploy.
    I use the JBuilder platform ,weblogic server,but I dot know how to deploy the JNDI ,please tell me ,thanks.

    this is the weblogic-ejb-jar.xml:
    <weblogic-ejb-jar>
        <weblogic-enterprise-bean>
            <ejb-name>test1</ejb-name>
            <jndi-name>test1</jndi-name>
        </weblogic-enterprise-bean>
    </weblogic-ejb-jar>

    my servlet source:the getTest() method is a Local method

    Context ctx = new InitialContext();
    test1Home test1home = (test1Home) ctx.lookup("java:comp/env/ejb/test1");
    String testok = test1home.create().getTest();

    Threaded Messages (4)

  2. JNDI question?[ Go to top ]

    You can only use the local interface between ejbs that are running in the same container. You can't use the local interface between servlets and ejbs. Try using the remote interface in your servlet and it should work.

    Dave
  3. JNDI question?[ Go to top ]

    If everything is deployed in an EAR file, you can use Local interfaces to access EJB from the servlet
  4. JNDI question?[ Go to top ]

    In order for your lookup to work you will also need an <ejb-local-ref> in your web.xml for the servlet:

    <ejb-local-ref>
      <ejb-ref-name>ejb/test1</ejb-ref-name>
      <ejb-ref-type>Session</ejb-ref-type>
      <local-home> classname of local home interface </local-home>
      <local> classname of local interface </local>
    </ejb-local-ref>
  5. JNDI question?[ Go to top ]

    U can use the following piece in the weblogic-ejb-jar.xml

    <weblogic-enterprise-bean>
        <ejb-name>UserManager</ejb-name>
        <local-jndi-name>UserManager</local-jndi-name>
    </weblogic-enterprise-bean>

    and do the lookup in the servlet like this:

    public synchronized static UserManagerLocalHome getUserManager()
        {
            
            UserManagerLocalHome home;
            try
            {
                    // Find the User Manager home object through JNDI.
                    Context ctx = (Context) new InitialContext();
                    home = (UserManagerLocalHome) ctx.lookup("UserManager");
                    homes.put("UserManager", home);
               
            }
            catch (Exception e)
            {
                System.out.println("Problem creating local home object for UserManager.");
            }
        
            return home;
        }

    u need not use any url like "java:comp/env/ejb/test1" as u r executing the servlet in the same environment as the ejbs


    Hope this helps,
    Seshu