6 Replies Latest reply on Jun 26, 2012 8:57 AM by nicolas duminil

    Cannot use ConsumerTemplate in route

    nicolas duminil Master

      Greetings,

       

      I have the following  route:

       

            from(

                "file:...")

                .split(body().tokenize("\n"))

                .streaming()

                .process(new FileConsumer())

      ..........................................................

       

      and the following camel context:

       

         

       

      The FileConsumer looks like this:

       

      public class FileConsumer implements Processor

      {

        private ConsumerTemplate consumerTemplate;

       

        public ConsumerTemplate getConsumerTemplate()

        {

          return consumerTemplate;

        }

       

        public void setConsumerTemplate(ConsumerTemplate consumerTemplate)

        {

          this.consumerTemplate = consumerTemplate;

        }

      .............................................

       

      Running the route with camel:run raises the following exception:

       

      Error occurred while running main from: org.apache.camel.spring.Main

      java.lang.reflect.InvocationTargetException

           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

           at java.lang.reflect.Method.invoke(Method.java:597)

           at org.apache.camel.maven.RunMojo$1.run(RunMojo.java:440)

           at java.lang.Thread.run(Thread.java:662)

      Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'fileConsumerBean' defined in file : Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'fileConsumer' of bean class : Bean property 'fileConsumer' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1361)

           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)

           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)

           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)

           at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)

           at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)

           at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)

           at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)

           at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)

           at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)

           at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)

           at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:93)

           at org.apache.camel.spring.Main.createDefaultApplicationContext(Main.java:186)

           at org.apache.camel.spring.Main.doStart(Main.java:140)

           at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:60)

           at org.apache.camel.main.MainSupport.run(MainSupport.java:140)

           at org.apache.camel.main.MainSupport.run(MainSupport.java:326)

           at org.apache.camel.spring.Main.main(Main.java:73)

           ... 6 more

      Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'fileConsumer' of bean class : Bean property 'fileConsumer' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

           at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1024)

           at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:900)

           at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:76)

           at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58)

           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1358)

           ... 24 more

      *************************************

       

      However, the parametter type of the setter correctly matches the return type of the getter.

       

      What could be wrong here ?

       

      Many thanks in advance.

       

      Kind regards,

       

      Nicolas