4 Replies Latest reply: Mar 10, 2014 7:23 PM by df0d0f92-b184-49ba-b25a-9a8c3864862f RSS

    I can't lookup EJB (3.0) in WebLogic 12 using ENC

    df0d0f92-b184-49ba-b25a-9a8c3864862f

      I have a simple application divided in 2 modules:

      • HolaMundo - Servlet component
      • SimpleEJB - EJB Component

       

      The EJB Component use EJB 3.0. I created a local business interface with one method. A stateless EJB that implement that interface. And I use the ejb-jar.xml for declare it.

      And a Servlet that use the EJB.

       

      In Glassfish or Tomee this way for working with EJB works, but i don't understand why it doesn't work in WebLogic 12...

       

      When i try to access to the servlet, i get an error. this is the error:

       

       

      javax.naming.NameNotFoundException: While trying to look up /app/SimpleEJB/Example!com.edwin.ejb.ExampleLocal in /app/webapp/HolaMundo.war/1051995086.; remaining name '/app/SimpleEJB/Example!com/edwin/ejb/ExampleLocal'
        at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:1180)
        at weblogic.jndi.internal.ApplicationNamingNode.lookup(ApplicationNamingNode.java:146)

       

      Servlet:

       

       

      package servlet;
      
      import java.io.IOException;
      import java.io.PrintWriter;
      
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      import javax.servlet.ServletException;
      import javax.servlet.http.HttpServlet;
      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;
      
      import com.edwin.ejb.ExampleLocal;
      
      public class EJB extends HttpServlet {
         private static final long serialVersionUID = 1L;
      
         @Override
         protected void doGet(HttpServletRequest arg0, HttpServletResponse arg1)
         throws ServletException, IOException {
      
         PrintWriter out = arg1.getWriter();
      
         ExampleLocal el2;
         try {
        el2 = (ExampleLocal) new InitialContext()
         .lookup("java:app/SimpleEJB/Example!com.edwin.ejb.ExampleLocal");
      
         out.println("EJBBBB: " + el2.nombre());
         } catch (NamingException e) {
        e.printStackTrace();
         }
         }
      
      }

       

      Local business interface:

       

      package com.edwin.ejb;
      
      public interface ExampleLocal {
      
          public String nombre();
      
      }
      

      EJB Stateless:

       

      package com.edwin.ejb;
      public class Example implements ExampleLocal{
      
          @Override
          public String nombre() {
              return "Edwin"; 
          }
      }
      

      ejb-jar.xml:

       

      <?xml version="1.0" encoding="UTF-8"?>
      <ejb-jar version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
        <display-name>SimpleEJB </display-name> 
        <enterprise-beans>
      
      
          <session>
              <ejb-name>Example</ejb-name>
              <business-local>com.edwin.ejb.ExampleLocal</business-local>
              <ejb-class>com.edwin.ejb.Example</ejb-class>
              <session-type>Stateless</session-type>
          </session>
        </enterprise-beans>
       </ejb-jar>