title: EJB reference configuration
body: <p>I am currently working on my first Java EE application and I’m facing some injection problems.</p>
  
  <p>For my project I am using JPA, EJB’s and Servlets.
  So far I created my entities, the generic DAO, DAO implementation, the services, then the servlet and a jsp page.</p>
  
  <p>I want to inject the JPA entity manager in my DAO classes.
  The DAO classes are injected into Services, and the Services are injected into Servlets.</p>
  
  <ol>
  <li><p>The generic DAO interface</p>
  
  <pre><code>@Local
  public interface DAO&lt;T&gt; {
      void insert(T item);
      void delete(T item);
  // and so on … }
  </code></pre></li>
  <li><p>The generic DAO implementation</p>
  
  <pre><code>public class GenericDAO&lt;T&gt; implements DAO&lt;T&gt; {
      @PersistenceContext(unitName = "MyPU")
      private EntityManager entityManager;
      private final Class&lt;T&gt; entityClass;
      public GenericDAO(Class&lt;T&gt; entityClass) {
          this.entityClass = entityClass;
      }
      @Override
      public void insert(T item) {
          entityManager.persist(item);
      }
  // and so on… }
  </code></pre></li>
  <li><p>Generic dao extension for my entity</p>
  
  <pre><code>@Stateless
  @LocalBean
  public class PositionDAO extends GenericDAO&lt;Position&gt; {
      public PositionDAO() {
          super(Position.class);
      }
  }
  </code></pre></li>
  <li><p>My service interface for Position entity</p>
  
  <pre><code>@Local
  public interface PositionService {
      void addPosition(Position position);
      void updatePosition(Position position);
      // and so on … }
  </code></pre></li>
  <li><p>My Service impl</p>
  
  <pre><code>@Stateless
  @LocalBean
  public class PositionServiceImpl implements PositionService {
      @EJB
      private DAO&lt;Position&gt; positionDao;
      @Override
      public void addPosition(Position position) {
          positionDao.insert(position);
      }  // and so on…
  
  @WebServlet(name = "RegisterServlet", urlPatterns = {"/register"})
  public class RegisterServlet extends HttpServlet {
      @EJB
      PositionService positionService;
  </code></pre></li>
  </ol>
  
  
  
  <pre><code>Cannot resolve reference Local ejb-ref name=online.recruitment.system.service.PositionServiceImpl/positionDao,Local 3.x interface =online.recruitment.system.dao.DAO,ejb-link=null,lookup=,mappedName=,jndi-name=,refType=Session
  </code></pre>
  
  <p>I put this config in my web.xml but it doesn't work</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;ejb-local-ref&gt;
      &lt;ejb-ref-name&gt;positionDao&lt;/ejb-ref-name&gt;
      &lt;ejb-ref-type&gt;Session&lt;/ejb-ref-type&gt; 
      &lt;local&gt;online.recruitment.system.dao.DAO&lt;/local&gt;
   &lt;/ejb-local-ref&gt;
  </code></pre>