我一直在阅读关于Camel属性的以下页面:
http://camel.apache.org/using-propertyplaceholder.html并且还阅读了“Camel In Action”一书.
我发现“Camel In Action”的第6章在定义Camel属性方面非常有用,我可以从config.properties加载以下三个属性:
config.timeout=10000
config.numSamples=1000
config.defaultViz=a
当我运行我的Java代码时,我能够在applicationContext.xml中的camel路由中看到以下三个值,如下面的线程#0消息所示:
14669 [Camel (HelloWorldContext) thread #0 - timer://hello.world.request.timer] INFO route1 - printing values read from config.properties file
14669 [Camel (HelloWorldContext) thread #0 - timer://hello.world.request.timer] INFO route1 - config.timeout= 10000
14669 [Camel (HelloWorldContext) thread #0 - timer://hello.world.request.timer] INFO route1 - config.numSamples= 1000
14670 [Camel (HelloWorldContext) thread #0 - timer://hello.world.request.timer] INFO route1 - config.defaultViz= a
但是,当我尝试将变量{{config.defaultViz}}传递给我的SensorGenerator Java类中名为defaultViz的String,并打印该字符串时,我在控制台上获得“{{config.defaultViz}}”而不是包含的值在{{config.defaultViz}}内.
换句话说,这就是我在屏幕上看到的内容:
Returning List
defaultViz= {{config.defaultViz}}
但我真的想在屏幕上看到这个:
Returning List
defaultViz=a
那么我在applicationContext.xml中做错了什么?
更新:问题是我需要在Spring和Camel之间添加一个Bridge,如上面引用的链接中所述.
这是我的UPDATED applicationContext.xml和桥:
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">
class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor" />
uri="timer://hello.world.request.timer?fixedRate=true&period={{config.timeout}}" />
class="org.apache.camel.component.properties.PropertiesComponent">