title: Problems with resource injection in EJBs
body: <p>Im having troubles to get my connection factory using annotation resource.
  It works well with the JNDI lookup but it does not with the annotation, my connection factory is null.</p>
  
  <p>This is my code with the JNDI lookup (works) :</p>
  
  <pre><code>ConnectionFactory factory = (ConnectionFactory)context.lookup("/ConnectionFactory");
  </code></pre>
  
  <p>This is my code with the annotation :</p>
  
  <pre><code>@Resource(mappedName = "java:/ConnectionFactory")
  private ConnectionFactory factory;
  </code></pre>
  
  <p>I ve tried with different mappedName as : /ConnectionFactory, java:/JmsXA, JmsXA etc. but still nullpointerexception :-/.</p>
  
  <p>If someone has an idea ...</p>
  
  <p>Thx !</p>
  
  <p>This is my class : </p>
  
  <pre><code>@Stateless
  public class ModuleCommunicationHandler implements IModuleCommunicationHandler
  {
  
    /** The connection factory. */
    @Resource(mappedName = "java:/ConnectionFactory")
    private ConnectionFactory factory;
  
  ...........
  
  /**
  * {@inheritDoc}
  */
  @Override
  public void sendMessage(JMSMessage jmsMessage, int deliveryMode, int acknowledgeMode) throws TechnicalException
  {
  
  try
  {
    context = new InitialContext();
  
    factory = (ConnectionFactory)context.lookup("/ConnectionFactory");
  
    // Setting the destination - Topic or Queue
    destination = (Destination)context.lookup(jmsMessage.getDestination());
  
    connection = factory.createConnection();
    session = connection.createSession(false, acknowledgeMode);
  
    sender = session.createProducer(destination);
    connection.start();
  
    // Creating the message
    message = session.createTextMessage();
    message.setText(jmsMessage.getBodyMessage());
  
    // Sending the message
    sender.setDeliveryMode(deliveryMode);
    sender.send(message);
  
  .....
  </code></pre>
  
  <p>And this is the log : </p>
  
  <pre><code>15:05:32,609 ERROR [STDERR] com.*.*.*.server.exception.ModuleCommunicationException: java.lang.NullPointerException
  15:05:32,609 ERROR [STDERR]     at com.*.*.*.server.service.ModuleCommunicationHandler.sendMessage(ModuleCommunicationHandler.java:147)
  15:05:32,664 ERROR [STDERR] Caused by: java.lang.NullPointerException
  15:05:32,664 ERROR [STDERR]     at com.*.*.*.server.service.ModuleCommunicationHandler.sendMessage(ModuleCommunicationHandler.java:108)
  </code></pre>