0

I am newbie in java EE . Recently I'm working on a project using bean stateless but i got the following error

Bean :

@Stateless(mappedName = "FlightServiceBean")
public class FlightServiceBean {

    public FlightServiceBean() {
    }

    // data

}

Servlet :

  private FlightServiceBean fs = null;

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {

        PrintWriter out = response.getWriter();
        out.println("The flights details servlet has been called ...");

        try
        {
            Context context = new InitialContext();
            fs = (FlightServiceBean) context.lookup("java:global/ejb1/FlightServiceBean!com.airline.service.FlightServiceBean");
// here where I got the exception
        }
        catch (NamingException e)
        {
            System.out.println("Naming Exception has occurred when trying to lookup the flightService EJB");
            e.printStackTrace();
        }

javax.naming.NamingException: Lookup failed for 'java:global/ejb1/FlightServiceBean!com.airline.service.FlightServiceBean' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: ejb1]

This is my project structure

Note: I am using glassfish 5.0 and jdk 1.8.0

Mohammad Ismail
  • 103
  • 2
  • 8

1 Answers1

0

Your EJB lookup is not proper. Try to change the above line to

 fs = (FlightServiceBean) ic.lookup("java:comp/env/ejb/FlightServiceBean");

For more on EJB Lookup, refer this link.

RLD
  • 1,867
  • 3
  • 15
  • 20
  • Refer the link specified by me and the one by paisanco. Else attach your deployment descriptor and other config files to troubleshoot the issue. – RLD Jun 09 '19 at 19:16
  • This is the way we did JNDI lookups about fifty years ago. The OP is using a modern server implementation. – Steve C Jun 12 '19 at 15:16