Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

EJB JNDI Exception

Options
  • 06-01-2003 3:59pm
    #1
    Moderators, Category Moderators, Technology & Internet Moderators Posts: 6,265 CMod ✭✭✭✭


    Hi,

    I'm new to EJB and am currently writing my first bean, using the Sun Reference Implementation J2EE Server and deployment tool. I'm using examples provided in chapter 2 of the Wrox book "Professional EJB" to get me started.

    I have successfully written, compiled and deployed the application on the server, and now wish to test it using the example Java Client in the book. My Bean name is Salary, and is registered in the JNDI Server as Salary too, to keep things simple.

    The client code is as follows:

    try {
    InitialContext ctx = new InitialContext();
    Object objRef = ctx.lookup("Salary");

    SalaryHome home = (SalaryHome
    javax.rmi.PortableRemoteObject.narrow(
    objRef, SalaryHome.class);

    Salary bean = home.create();

    System.out.println("Monthly net salary: " +
    bean.calculateSalary(28000, 2, 500));

    } catch (javax.naming.NamingException ne) {
    System.out.println("Naming Exception caught: " + ne);
    } catch (javax.ejb.CreateException ce) {
    System.out.println("Create Exception caught: " + ce);
    } catch (java.rmi.RemoteException re) {
    System.out.println("Remote Exception caught: " + re);
    }

    When I attempt to run my client (which is one the same machine as the J2ee server) I get the following JNDI error:

    C:\ProEJB\Chapter2\code>java SalaryClient
    Naming Exception caught: javax.naming.NameNotFoundException: Salary not found

    Since I have copied the example code exactly, I can only assume it's a problem with my JNDI Server configuration. Can anyone help????


Comments

  • Registered Users Posts: 1,994 ✭✭✭lynchie


    AFAIK, If your using the sun J2EE Server, all beans are bound to the following context within the JNDI tree java:comp/env/ejb/

    Thus your code should be
    Object objRef = ctx.lookup("java:comp/env/ejb/Salary");

    Check out
    the J2EE Tutorial for more info.


Advertisement