java camel from uri_java – 如何将Camel属性加载到Bean中?
我一直在閱讀關(guān)于Camel屬性的以下頁(yè)面:
http://camel.apache.org/using-propertyplaceholder.html并且還閱讀了“Camel In Action”一書.
我發(fā)現(xiàn)“Camel In Action”的第6章在定義Camel屬性方面非常有用,我可以從config.properties加載以下三個(gè)屬性:
config.timeout=10000
config.numSamples=1000
config.defaultViz=a
當(dāng)我運(yùn)行我的Java代碼時(shí),我能夠在applicationContext.xml中的camel路由中看到以下三個(gè)值,如下面的線程#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
但是,當(dāng)我嘗試將變量{{config.defaultViz}}傳遞給我的SensorGenerator Java類中名為defaultViz的String,并打印該字符串時(shí),我在控制臺(tái)上獲得“{{config.defaultViz}}”而不是包含的值在{{config.defaultViz}}內(nèi).
換句話說(shuō),這就是我在屏幕上看到的內(nèi)容:
Returning List
defaultViz= {{config.defaultViz}}
但我真的想在屏幕上看到這個(gè):
Returning List
defaultViz=a
那么我在applicationContext.xml中做錯(cuò)了什么?
更新:問(wèn)題是我需要在Spring和Camel之間添加一個(gè)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">
總結(jié)
以上是生活随笔為你收集整理的java camel from uri_java – 如何将Camel属性加载到Bean中?的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: java元空间扩容_JVM元空间(Met
- 下一篇: java题目不会做那么解答_有几道JAV