title: EJB3 - obtaining bean via injection vs lookup - what are the differences, implications, gotchas?
body: <p>There are two ways I know of to obtain an EJB instance:</p>
  
  <ul>
  <li>dependency injection in servlets and EJBs via the @EJB annotation</li>
  <li>JNDI lookup via Context.lookup anywhere</li>
  </ul>
  
  <p>What are the differences, implications and gotchas in using either of these approaches? Are they the same? Is dependency injection faster than lookup? What about transaction handling and object lifecycle management?</p>
  
  <p>Things I'm aware of include:</p>
  
  <p>annotation</p>
  
  <ul>
  <li>works with servlets and and EJBs only</li>
  <li>convenient syntax</li>
  <li>container independent</li>
  </ul>
  
  <p>lookup</p>
  
  <ul>
  <li>can instantiate different implementations of the EJB interface programatically at run time.</li>
  <li>works from anywhere - e.g. POJOs.</li>
  <li>depends on naming convention of container</li>
  </ul>