title: NameAlreadyBoundException using JNDI
body: <p>I created a session bean with this code:</p>
  
  <pre><code>package ejb2;
  import javax.annotation.Resource;
  import javax.ejb.SessionContext;
  import javax.ejb.Stateless;
  
  @Stateless(name = "TestEJB", mappedName = "EJB2-Project1-TestEJB")
  public class TestEJBBean implements TestEJB, TestEJBLocal {
      @Resource
      SessionContext sessionContext;
  
      public TestEJBBean() {
      }
  
      public String getHello(String who_welcome) {
          return "Hello " + who_welcome;
      }
  }
  </code></pre>
  
  <p>As you can see, it's almost a default code (except getHello method). Besides this bean I have a client:</p>
  
  <pre><code>package ejb2;
  
  import java.util.Hashtable;
  
  import javax.naming.CommunicationException;
  import javax.naming.Context;
  import javax.naming.InitialContext;
  import javax.naming.NamingException;
  
  public class TestEJBClient {
      public static void main(String[] args) {
          try {
              final Context context = getInitialContext();
              TestEJB testEJB = (TestEJB) context.lookup("EJB2-Project1-TestEJB#ejb2.TestEJB");
              System.out.println(testEJB.getHello("Student"));
          } catch (CommunicationException ex) {
              System.out.println(ex.getClass().getName());
              System.out.println(ex.getRootCause().getLocalizedMessage());
              System.out.println("\n*** A CommunicationException was raised.  This typically\n*** occurs when the target WebLogic server is not running.\n");
          } catch (Exception ex) {
              ex.printStackTrace();
          }
      }
  
      private static Context getInitialContext() throws NamingException {
          Hashtable env = new Hashtable();
          // WebLogic Server 10.x/12.x connection details
          env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
          env.put(Context.PROVIDER_URL, "t3://localhost:7101");
          return new InitialContext(env);
      }
  }
  </code></pre>
  
  <p>First time it worked like a charm. But then I created another bean:</p>
  
  <pre><code>package ejb2;
  import javax.annotation.Resource;
  import javax.ejb.Stateless;
  import javax.ejb.SessionContext;
  import javax.naming.Context;
  import javax.naming.InitialContext;
  
  @Stateless(name = "ClientEJB", mappedName = "EJB2-Project1-ClientEJB")
  public class ClientEJBBean implements ClientEJB, ClientEJBLocal {
      @Resource
      SessionContext sessionContext;
      TestEJB testEJB;
  
      public ClientEJBBean() {
          try {
              final Context context = new InitialContext();
              testEJB = (TestEJB) context.lookup("EJB2-Project1-TestEJB#ejb2.TestEJB");
          } catch (Exception ex) {
              ex.printStackTrace();
          }
      }
  
      public String getHelloFromBean(String who) {
          return testEJB.getHello(who);
      }
  }
  </code></pre>
  
  <p>And now beans aren't working. I get an error like this:</p>
  
  <p>weblogic.application.ModuleException: Unable to bind Business Interface to the JNDI name: EJB2Project1WebApp_warClientEJB_Home, throw exception javax.naming.NameAlreadyBoundException: [EJB:011224]Unable to bind the interface ejb2.ClientEJB to ClientEJB. Another EJB has already bound an interface to that name.; remaining name 'EJB2-Project1-ClientEJB#ejb2'. NestedException Message is :[EJB:011224]Unable to bind the interface ejb2.ClientEJB to ClientEJB. Another EJB has already bound an interface to that name.</p>
  
  <p>What's the problem with these codes?</p>