Jussi Nupponen created CAMEL-9866:
-------------------------------------
Summary: @PropertyInject doesn't work with Spring-Boot
Key: CAMEL-9866
URL: https://issues.apache.org/jira/browse/CAMEL-9866
Project: Camel
Issue Type: Bug
Components: camel-core
Affects Versions: 2.17.0, 2.16.3
Reporter: Jussi Nupponen
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
{code:java}
@SpringBootApplication
public class MySpringBootRouter extends FatJarRouter {
@PropertyInject("inject-value")
private String injectedValue;
@Override
public void configure() {
from("timer:trigger")
.log("PropertyInject: "+injectedValue);
}
}
{code}
Running the code above with command
{noformat}
mvn spring-boot:run
{noformat}
causes the following exception:
{noformat}
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
{noformat}
Using placeholders like {noformat}.log("{{inject-value}}"){noformat} 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
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)