Initial Context Error

Discussions

EJB design: Initial Context Error

  1. Initial Context Error (1 messages)

    Hi, I'm using JDeveloper, Struts, JBoss 3.2.1

    I deploy a session bean and I don´t received any error on jboss, but when I call an action that use the initial context to use the session bean I recived this error:

    **************************************************
    LoginSessionEJB not bound.
    **************************************************

    this is my ejb-jar.xml:

    **************************************************
    <ejb-jar>
      <enterprise-beans>
        <session>
          <description>Session Bean ( Stateless )</description>
          <display-name>LoginSessionEJB</display-name>
          <ejb-name>LoginSessionEJB</ejb-name>
          <home>model.LoginSessionEJBHome</home>
          <remote>model.LoginSessionEJB</remote>
          <ejb-class>model.LoginSessionEJBBean</ejb-class>
          <session-type>Stateless</session-type>
          <transaction-type>Bean</transaction-type>
        </session>
      </enterprise-beans>
    </ejb-jar>
    **************************************************

    Use of the initialContext on a Action class:

    **************************************************
    Context ctx = getInitialContext();
                  
    Object objref = ctx.lookup("LoginSessionEJB");
    loginHome = (LoginSessionEJBHome) PortableRemoteObject.narrow(
                                                           objref, LoginSessionEJBHome.class);
                loginRemote = loginHome.create();
    **************************************************

    This is the function of getInitialContext():


    **************************************************

            Properties properties = null;
            try {
              properties = new Properties();
              properties.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
              properties.put("java.naming.provider.url", "jnp://localhost:1099");
              properties.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
              
            }
            catch (Exception ex) {
            }
        return new InitialContext(properties);

    **************************************************

    The lookup don´t foud my bean, how I can solve this problem?

    Thanks, Regards Daniel

    Threaded Messages (1)

  2. Initial Context Error[ Go to top ]

    Hi Daniel,
    From your code it seems that you are using EJB-NAME/DisplayName to lookup the EJB in the JNDI tree of your application server which is JBOSS..
    You need to lookup the EJB with its JNDI name. This <jndi-name> needs to be specified in the EJB's application server specific deployment descriptor. ejb-jar.xml is a common Deployment Descriptor file. <jndi-name> wont come in this file.
    For e.g:- For Weblogic application server we need to specify the jndi-name in weblogic-ejb-jar.xml file.
    Find such a similar deployment descriptor file for JBoss.
    Also One more thing you can do is that try to analyse the log file of JBoss. There you will certainly find log entry which will say that LoginEJB is deployed and bound to XYZ name.
    Let me know if this solves ur problem.
    Thanks
    Amit