1 Reply Latest reply on Jul 19, 2011 6:53 PM by clebert.suconic

    Can't find ConnectionFactory

    deege

      Hi,

       

      I'm creating the message producer in a JMS client app a little different than the examples.  I'm trying to use injection with the Java annotations. This is what I'm trying to use to post messages to a queue.

       

       

      public class HornetProducer {
             @Resource(mappedName="ConnectionFactory")
                private static ConnectionFactory connectionFactory;
        
                @Resource(mappedName="queue/Queue")
              private static Queue queue;
        
        /**
                 * @param args
                 */
                public static void main(String[] args) {
                          Connection connection;
                          try {
                                    connection = connectionFactory.createConnection();
                                    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
                                    MessageProducer producer = session.createProducer(queue);
                                    TextMessage message = session.createTextMessage();
        
                                    for (int i = 0; i < 10; i++) { 
                                        message.setText("This is message " + (i + 1)); 
                                        System.out.println("Sending message: " + message.getText()); 
                                        producer.send(message);
                                    }
        
                                      // end message
                                    producer.send(session.createMessage());
        
                          } catch (JMSException e) {
                                    e.printStackTrace();
                          }  
                }
      }
      
      

       

      I'm running HornetQ as a standalone app.  I've created a queue and connection factory in hornetq-jms.xml as listed below

       

      <connection-factory name="ConnectionFactory"> 
             <connectors>
                <connector-ref connector-name="netty"/> 
             </connectors> 
             <entries>
                <entry name="ConnectionFactory"/> 
             </entries>
      </connection-factory>
      
      
      <queue name="Queue"> 
          <entry name="/queue/Queue"/>
      </queue> 
      
      

       

      When I try running this, it looks like the connection factory and queue are never injected.  The connection factory is null when it's trying to create a connection.

       

      I also created a jndi.properties file, and put it in the classpath.

       

      Is there something I'm missing?  Is there something else I need to configure?

       

      Thanks,

      DJ Spiess