I read the following page about Camel properties: http://camel.apache.org/using-propertyplaceholder.html , and also read the book "Camel in Action".
I found Chapter 6 of "Camel In Action" very useful in defining Camel properties, and I can load the following three properties from my config.properties:
config.timeout=10000 config.numSamples=1000 config.defaultViz=a
When I run my Java code, I can see the following three values ββinside my camel route in my applicationContext.xml, as shown in thread # 0 messages below:
14669 [Camel (HelloWorldContext) thread
However, when I try to pass the variable {{config.defaultViz}} to a String named defaultViz in my Java SensorGenerator class and print this line, I get "{{config.defaultViz}}" in the console instead of the value contained in {{config .defaultViz}}.
In other words, this is what I see on the screen:
Returning List defaultViz= {{config.defaultViz}}
But I really want to see this on the screen:
Returning List defaultViz=a
So what am I doing wrong in my applicationContext.xml?
UPDATED: The problem was that I needed to add a bridge between Spring and Camel, as indicated in the link I referenced above.
Here is my UPDATED applicationContext.xml with the bridge:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel="http://camel.apache.org/schema/spring" xmlns:context="http://www.springframework.org/schema/context" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor" /> <context:component-scan base-package="com.data.world2" /> <context:annotation-config /> <camel:camelContext id="HelloWorldContext"> <camel:dataFormats> <camel:json id="jack" library="Jackson"/> </camel:dataFormats> <camel:route> <camel:from uri="timer://hello.world.request.timer?fixedRate=true&period={{config.timeout}}" /> <camel:to uri="log:hello.world.request?level=INFO&showAll=true" /> <camel:bean ref="helloWorld" /> <camel:marshal ref ="jack"/> <camel:convertBodyTo type="java.lang.String" /> <camel:log message="${body}"/> <camel:log message="printing values read from config.properties file"/> <camel:log message="config.timeout= {{config.timeout}}"/> <camel:log message="config.numSamples= {{config.numSamples}}"/> <camel:log message="config.defaultViz= {{config.defaultViz}}"/> <camel:to uri="log:hello.world.response?level=INFO&showAll=true" /> </camel:route> </camel:camelContext> <util:properties id="sensorProperties" location="classpath:/sensor.properties"/> <bean class="com.data.world2.SensorGenerator"> <property name="sourceProperties" ref="sensorProperties" /> <property name="defaultViz" value="${config.defaultViz}"/> </bean> <bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent"> <property name="location" value="classpath:config.properties"/> </bean> <bean id="bridgePropertyPlaceholder" class="org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer"> <property name="location" value="classpath:config.properties"/> </bean> </beans>
I found this question similar, but not quite the same: Embedding a property in a bean