spring 如何使camel简单表达式与spring xml中的属性占位符一起使用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22002028/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to make camel simple expression work with property placeholder in spring xml
提问by David
I am trying to using property placeholder in camel route. I have test.properties which define property: MQ.queuename1=TESTQUEUE. In camel context, i define placeholder:
我正在尝试在骆驼路线中使用属性占位符。我有定义属性的 test.properties:MQ.queuename1=TESTQUEUE。在骆驼上下文中,我定义占位符:
<camel:camelContext xmlns="http://camel.apache.org/schema/spring" >
<propertyPlaceholder id="camel-properties" location="file:${web.external.propdir}/test.properties"/>
In the route, i use simple expresion to evaluate the property:
在路由中,我使用简单的表达式来评估属性:
<choice>
<when>
<simple>${in.header.queuename} == '{{MQ.queuename1}}'</simple>
<bean ref="ExtractOrderContent" method="extractContent"/>
<to uri="websphere-mq:queue:TESTQUEUE" pattern="InOnly"/>
</when>
</choice>
When i run camel, the property file is recognized by camel but it looks like the simple expression doesn't work. Do i miss anything?
当我运行camel时,camel识别了属性文件,但看起来简单的表达式不起作用。我想念什么吗?
回答by Claus Ibsen
You can use the properties function from simple (http://camel.apache.org/simple)
您可以使用 simple ( http://camel.apache.org/simple) 中的属性功能
<simple>${in.header.queuename} == ${properties:MQ.queuename1}</simple>
The {{ }} in nested < when > is likely due to a bug, that has been fixed in newer Camel releases.
嵌套 < when > 中的 {{ }} 可能是由于一个错误,该错误已在较新的 Camel 版本中修复。
回答by Hussain Pirosha
From the route configuration that you have provided, It seems that you missed out setting queuename in header. Instead you should use properties component as
从您提供的路由配置来看,您似乎错过了在标头中设置 queuename 的问题。相反,您应该使用属性组件作为
<simple>${properties:queuename} == 'MQ.queuename1'</simple>
<simple>${properties:queuename} == 'MQ.queuename1'</simple>