title: How to inject EJB in java web service SOAP
body: <p>i'm triyng to develop a simple web service in Java that used an EJB, with EJBs in jar file and WebServices in war file, both packaged in one ear. We use EjB 3.0 on JBOSS-AS 7.1.</p>
  
  <p><strong>Here my EJB class with its interface :</strong></p>
  
  <pre><code>@Stateless
  public class TestEjb implements ITestEjb {
  
      public boolean authentifier(String login, String password) {
          if(login.equals("nico") &amp;&amp; password.equals("nr"))
              return true;
          else 
              return false;
      }
  
  }
  
  @Local
  public interface ITestEjb {
      public boolean authentifier(String login, String password);
  }
  </code></pre>
  
  <p><strong>And here is my <em>web service</em> which inject the <em>previous EJB</em> :</strong></p>
  
  <pre><code>//@Stateless
  @WebService
  @SOAPBinding(style = Style.RPC)
  public class AuthentificationWS {
      @EJB
      private ITestEjb testEjb;
  
     public boolean authentifier(String login,String password) {
         return testEjb.authentifier(login, password);
     }
  }
  </code></pre>
  
  <p>The deployment works well but when i call my web service, <strong>the EJB is always <em>null</em></strong><br/> <code>(error : java.nullpointerException).</code></p>
  
  <p>So i tried to add a <code>@Stateless</code> to my web Service to convert it to EJB but without success when i try to consume it by a web service client. </p>
  
  <p>Then i tried to access Ejb by <strong><em>local jndi lookup</em></strong> like below, taking the local jndi url in JBOSS log :</p>
  
  <pre><code>final String jndi = "java:module/TestEjb!fr.test.ITestEjb";
  testEjb = (ITestEjb) new InitialContext().lookup(jndi);
  </code></pre>
  
  <p>But it did not work.</p>
  
  <p>Finally i tried with the <strong><em>global jndi url</em></strong> like below :</p>
  
  <pre><code>final String jndi = "ejb:Num-ear-1.0.0-SNAPSHOT/Num-ejb-1/TestEjb!fr.test.ITestEjb"
  testEjb = (ITestEjb) new InitialContext().lookup(jndi);
  </code></pre>
  
  <p>And it works well !!</p>
  
  <p>So, i don't understand why my webservice cannot access locally to its EJB by injection or local Jndi way?</p>