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

Some attributes in spring camel xml can't be replaced by property placeholder when used in spring boot

    XMLWordPrintableJSON

    Details

    • Estimated Complexity:
      Unknown

      Description

      Everything initialized in org.apache.camel.core.xml.AbstractCamelContextFactoryBean.initCamelContext() using a spring camel xml with spring boot, can not contain a property otherwise this is the exception thrown:

      org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'camelMain': Invocation of init method failed; nested exception is java.lang.IllegalStateException: org.springframework.context.annotation.AnnotationConfigApplicationContext@1b99b9f8 has not been refreshed yet
              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583)
              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:202)
              at org.springframework.context.event.AbstractApplicationEventMulticaster.retrieveApplicationListeners(AbstractApplicationEventMulticaster.java:228)
              at org.springframework.context.event.AbstractApplicationEventMulticaster.getApplicationListeners(AbstractApplicationEventMulticaster.java:185)
              at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
              at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:382)
              at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:336)
              at org.springframework.boot.context.event.EventPublishingRunListener.finished(EventPublishingRunListener.java:93)
              at org.springframework.boot.SpringApplicationRunListeners.callFinishedListener(SpringApplicationRunListeners.java:79)
              at org.springframework.boot.SpringApplicationRunListeners.finished(SpringApplicationRunListeners.java:72)
              at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:813)
              at org.springframework.boot.SpringApplication.run(SpringApplication.java:326)
              at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186)
              at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175)
              at com.mycompany.Application.main(Application.java:34)
              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:506)
              at java.lang.Thread.run(Thread.java:748)
      Caused by: java.lang.IllegalStateException: org.springframework.context.annotation.AnnotationConfigApplicationContext@1b99b9f8 has not been refreshed yet
              at org.springframework.context.support.AbstractApplicationContext.assertBeanFactoryActive(AbstractApplicationContext.java:1063)
              at org.springframework.context.support.AbstractApplicationContext.getBeanNamesForType(AbstractApplicationContext.java:1177)
              at org.apache.camel.spring.CamelContextFactoryBean.getBeanForType(CamelContextFactoryBean.java:220)
              at org.apache.camel.core.xml.AbstractCamelContextFactoryBean.afterPropertiesSet(AbstractCamelContextFactoryBean.java:159)
              at org.apache.camel.spring.CamelContextFactoryBean.afterPropertiesSet(CamelContextFactoryBean.java:275)
              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1642)
              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1579)
              ... 25 common frames omitted
      14:12:57.942 [main] DEBUG o.s.b.d.LoggingFailureAnalysisReporter - Application failed to start due to an exception
      org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.apache.camel.CamelContext' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
              at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1466)
              at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1097)
              at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1059)
              at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:835)
              at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741)
              at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:467)
              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1128)
              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1022)
              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:512)
              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.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1076)
              at org.apache.camel.spring.spi.ApplicationContextRegistry.lookupByName(ApplicationContextRegistry.java:71)
              at org.apache.camel.impl.PropertyPlaceholderDelegateRegistry.lookupByName(PropertyPlaceholderDelegateRegistry.java:50)
              at org.apache.camel.util.CamelContextHelper.lookupPropertiesComponent(CamelContextHelper.java:575)
              at org.apache.camel.impl.DefaultCamelContext.resolvePropertyPlaceholders(DefaultCamelContext.java:2343)
              at org.apache.camel.util.CamelContextHelper.parseBoolean(CamelContextHelper.java:354)
              at org.apache.camel.core.xml.AbstractCamelContextFactoryBean.initCamelContext(AbstractCamelContextFactoryBean.java:769)
              at org.apache.camel.core.xml.AbstractCamelContextFactoryBean.afterPropertiesSet(AbstractCamelContextFactoryBean.java:322)
              at org.apache.camel.spring.CamelContextFactoryBean.afterPropertiesSet(CamelContextFactoryBean.java:275)
              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1642)
              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1579)
              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:202)
              at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1082)
              at org.apache.camel.spring.CamelBeanPostProcessor$1.getOrLookupCamelContext(CamelBeanPostProcessor.java:66)
              at org.apache.camel.impl.DefaultCamelBeanPostProcessor.postProcessBeforeInitialization(DefaultCamelBeanPostProcessor.java:87)
              at org.apache.camel.spring.CamelBeanPostProcessor.postProcessBeforeInitialization(CamelBeanPostProcessor.java:131)
              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:408)
              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1575)
              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:735)
              at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861)
              at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)
              at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761)
              at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371)
              at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
              at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186)
              at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175)
              at com.mycompany.Application.main(Application.java:34)
              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:506)
              at java.lang.Thread.run(Thread.java:748)
      14:12:57.943 [main] ERROR o.s.b.d.LoggingFailureAnalysisReporter - 
      
      ***************************
      APPLICATION FAILED TO START
      ***************************
      
      Description:
      
      Parameter 0 of method properties in org.apache.camel.spring.boot.CamelAutoConfiguration required a bean of type 'org.apache.camel.CamelContext' that could not be found.
              - Bean method 'camelContext' in 'CamelAutoConfiguration' not loaded because @ConditionalOnMissingBean (types: org.apache.camel.CamelContext; SearchStrategy: all) found bean 'camelMain'
      
      
      Action:
      
      Consider revisiting the conditions above or defining a bean of type 'org.apache.camel.CamelContext' in your configuration.
      
      [WARNING] 
      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:506)
              at java.lang.Thread.run(Thread.java:748)
      Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'template': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'camelMain': Invocation of init method failed; nested exception is org.apache.camel.RuntimeCamelException: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'properties' defined in class path resource [org/apache/camel/spring/boot/CamelAutoConfiguration.class]: Unsatisfied dependency expressed through method 'properties' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.apache.camel.CamelContext' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:562)
              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:735)
              at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861)
              at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)
              at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761)
              at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371)
              at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
              at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186)
              at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175)
              at com.mycompany.Application.main(Application.java:34)
              ... 6 more
      Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'camelMain': Invocation of init method failed; nested exception is org.apache.camel.RuntimeCamelException: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'properties' defined in class path resource [org/apache/camel/spring/boot/CamelAutoConfiguration.class]: Unsatisfied dependency expressed through method 'properties' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.apache.camel.CamelContext' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583)
              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:202)
              at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1082)
              at org.apache.camel.spring.CamelBeanPostProcessor$1.getOrLookupCamelContext(CamelBeanPostProcessor.java:66)
              at org.apache.camel.impl.DefaultCamelBeanPostProcessor.postProcessBeforeInitialization(DefaultCamelBeanPostProcessor.java:87)
              at org.apache.camel.spring.CamelBeanPostProcessor.postProcessBeforeInitialization(CamelBeanPostProcessor.java:131)
              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:408)
              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1575)
              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
              ... 20 more
      Caused by: org.apache.camel.RuntimeCamelException: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'properties' defined in class path resource [org/apache/camel/spring/boot/CamelAutoConfiguration.class]: Unsatisfied dependency expressed through method 'properties' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.apache.camel.CamelContext' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
              at org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1763)
              at org.apache.camel.impl.PropertyPlaceholderDelegateRegistry.lookupByName(PropertyPlaceholderDelegateRegistry.java:52)
              at org.apache.camel.util.CamelContextHelper.lookupPropertiesComponent(CamelContextHelper.java:575)
              at org.apache.camel.impl.DefaultCamelContext.resolvePropertyPlaceholders(DefaultCamelContext.java:2343)
              at org.apache.camel.util.CamelContextHelper.parseBoolean(CamelContextHelper.java:354)
              at org.apache.camel.core.xml.AbstractCamelContextFactoryBean.initCamelContext(AbstractCamelContextFactoryBean.java:769)
              at org.apache.camel.core.xml.AbstractCamelContextFactoryBean.afterPropertiesSet(AbstractCamelContextFactoryBean.java:322)
              at org.apache.camel.spring.CamelContextFactoryBean.afterPropertiesSet(CamelContextFactoryBean.java:275)
              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1642)
              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1579)
              ... 33 more
      Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'properties' defined in class path resource [org/apache/camel/spring/boot/CamelAutoConfiguration.class]: Unsatisfied dependency expressed through method 'properties' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.apache.camel.CamelContext' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
              at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749)
              at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:467)
              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1128)
              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1022)
              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:512)
              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.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1076)
              at org.apache.camel.spring.spi.ApplicationContextRegistry.lookupByName(ApplicationContextRegistry.java:71)
              at org.apache.camel.impl.PropertyPlaceholderDelegateRegistry.lookupByName(PropertyPlaceholderDelegateRegistry.java:50)
              ... 41 more
      Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.apache.camel.CamelContext' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
              at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1466)
              at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1097)
              at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1059)
              at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:835)
              at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741)
              ... 53 more
      

      basically spring while instantiating CamelContext for whatever is in initCamelContext() and need a property resolution will try to find a bean named "properties" and not finding it will try to instantiate it from org.apache.camel.spring.boot.CamelAutoConfiguration.properties(CamelContext camelContext, PropertiesParser parser) failing with the mentioned exception.

      If an explicit property placeholder is defined like:

      <propertyPlaceholder id="properties" location="application.properties"/>
      

      then all works fine.

      There is a simple reproducer attached.

        Attachments

        1. reproducer2.zip
          5 kB
          Andrea Tarocchi
        2. reproducer.zip
          5 kB
          Andrea Tarocchi

          Activity

            People

            • Assignee:
              davsclaus Claus Ibsen
              Reporter:
              valdar Andrea Tarocchi
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: