Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-9866

@PropertyInject doesn't work with Spring-Boot

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.16.3, 2.17.0
    • Fix Version/s: 2.16.4, 2.17.1, 2.18.0
    • Component/s: camel-spring-boot
    • Labels:
      None
    • Estimated Complexity:
      Unknown
    • Regression:
      Regression

      Description

      When I upgraded Camel Spring-Boot project to use Camel 2.16.3 from Camel 2.16.2 the @PropertyInject annotations broke.

      The problem occurs when using the annotation in a Spring-Boot application like this

      @SpringBootApplication
      public class MySpringBootRouter extends FatJarRouter {
      
          @PropertyInject("inject-value")
          private String injectedValue;
          
          @Override
          public void configure() {
              from("timer:trigger")
              .log("PropertyInject: "+injectedValue);
          }
      }
      

      Running the code above with command

      mvn spring-boot:run
      

      causes the following exception:

      java.lang.reflect.InvocationTargetException
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:498)
      	at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:478)
      	at java.lang.Thread.run(Thread.java:745)
      Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySpringBootRouter': Initialization of bean failed; nested exception is org.apache.camel.spring.GenericBeansException: Error post processing bean: mySpringBootRouter; nested exception is org.apache.camel.RuntimeCamelException: java.lang.IllegalArgumentException: Cannot add component as its already previously added: properties
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
      	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
      	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
      	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
      	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
      	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
      	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
      	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
      	at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
      	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766)
      	at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361)
      	at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
      	at org.apache.camel.spring.boot.FatJarRouter.main(FatJarRouter.java:26)
      	... 6 more
      Caused by: org.apache.camel.spring.GenericBeansException: Error post processing bean: mySpringBootRouter; nested exception is org.apache.camel.RuntimeCamelException: java.lang.IllegalArgumentException: Cannot add component as its already previously added: properties
      	at org.apache.camel.spring.CamelBeanPostProcessor.postProcessBeforeInitialization(CamelBeanPostProcessor.java:154)
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:408)
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570)
      	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
      	... 19 more
      Caused by: org.apache.camel.RuntimeCamelException: java.lang.IllegalArgumentException: Cannot add component as its already previously added: properties
      	at org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1680)
      	at org.apache.camel.impl.CamelPostProcessorHelper.getInjectionPropertyValue(CamelPostProcessorHelper.java:263)
      	at org.apache.camel.impl.DefaultCamelBeanPostProcessor.injectFieldProperty(DefaultCamelBeanPostProcessor.java:206)
      	at org.apache.camel.impl.DefaultCamelBeanPostProcessor$1.doWith(DefaultCamelBeanPostProcessor.java:172)
      	at org.apache.camel.util.ReflectionHelper.doWithFields(ReflectionHelper.java:73)
      	at org.apache.camel.impl.DefaultCamelBeanPostProcessor.injectFields(DefaultCamelBeanPostProcessor.java:168)
      	at org.apache.camel.impl.DefaultCamelBeanPostProcessor.postProcessBeforeInitialization(DefaultCamelBeanPostProcessor.java:82)
      	at org.apache.camel.spring.CamelBeanPostProcessor.postProcessBeforeInitialization(CamelBeanPostProcessor.java:148)
      	... 22 more
      Caused by: java.lang.IllegalArgumentException: Cannot add component as its already previously added: properties
      	at org.apache.camel.impl.DefaultCamelContext.addComponent(DefaultCamelContext.java:370)
      	at org.apache.camel.util.CamelContextHelper.lookupPropertiesComponent(CamelContextHelper.java:578)
      	at org.apache.camel.impl.CamelPostProcessorHelper.getInjectionPropertyValue(CamelPostProcessorHelper.java:237)
      	... 28 more
      

      Using placeholders like

      .log("{{inject-value}}")

      still works just as before. I tried to browse through changes between 2.16.2 and 2.16.3 but I didn't catch any obvious reason for this problem.

      I created a runnable demo of the problem here: https://github.com/jnupponen/camel-properties-component-spring-boot-problem

        Attachments

          Activity

            People

            • Assignee:
              trohovsky Tomas Rohovsky
              Reporter:
              jnupponen Jussi Nupponen
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: