5 Replies Latest reply on Dec 24, 2009 1:01 PM by rcasazza

    @Produce - producing null pointer

    rcasazza

      Hi,

       

      I'm not sure where I'm going wrong.

       

      I'm trying to use the @Produce annotation, following an example. Seems simple enough...

       

           public interface MyListener {

               String sayHello(String name);

           }

       

           @Produce(uri="test-jms:queue:test.queue")

           MyListener     producer;

            

           public void sendMsg() throws Exception {

                 

                producer.sayHello("Test Msg");

                 

           }

       

      In my main, I create the Camel Context, add the test-jms component.. start up the context... then I create the class containing sendMsg and call it... producer is null... I've not used annotations much before.. I still have to instantiate producer? The annotation doesn't do that for me, correct?

       

      Bob

        • 1. Re: @Produce - producing null pointer
          njiang

          Did you register the camel-jms component like this before you started the camel context ?

           

          CamelContext context = new DefaultCamelContext();
                  
          ConnectionFactory connectionFactory = new    ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
          
          context.addComponent("test-jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
          

           

          • 2. Re: @Produce - producing null pointer
            rcasazza

            I have a separate instance of ActiveMQ running and do the following in main:

             

            CamelContext cc = new DefaultCamelContext();

                       

            ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");

            cc.addComponent("activemq", JmsComponent.jmsComponent(connectionFactory));

                      cc.start();

             

            Then I instantiate the class with the @Produce... and call the method to put a message on the queue.

             

            So I'm not sure what I'm doing wrong. I've played with it some more, but are having no luck. I am using Camel 2.1, JDK 1.6

            • 3. Re: @Produce - producing null pointer
              davsclaus

              AFAIR you need to use camel-spring which creates those proxies for @Consumer and @Producer.

               

              As you need the IoC container to do it works with among others is the @Consumer stuff as well.

              • 4. Re: @Produce - producing null pointer
                njiang

                The annotation injection thing is done in BeanPostProcess, you can use this code on your DefaultCamelContext.

                        CamelBeanPostProcessor processor = new CamelBeanPostProcessor();
                        processor.setCamelContext(context);
                        // the bean that you want to inject
                        processor.postProcessBeforeInitialization(myBean, "myBean");
                

                 

                • 5. Re: @Produce - producing null pointer
                  rcasazza

                  That did it.