我正在尝试使用 Camel 路由来执行基于条件语句的操作;如果该条件为真,则它将执行该操作。但是,如果该条件为假,则不会执行该操作。
条件语句基于从“.properties”文件中提取的属性值。我定义了一个 placeholderPrefix
和 placeholderSuffix
对于 bean 中的属性是 {{
和 }}
分别。如果有帮助,该定义如下所示:
<bean id="com.example.springPropertyConfigurer"
class="com.example.PropertiesSpringPlaceholderConfigurer">
<constructor-arg index="0"
type="com.example.PropertiesInterface"
ref="com.example.Properties" />
<property name="placeholderPrefix" value="{{" />
<property name="placeholderSuffix" value="}}" />
<property name="ignoreUnresolvablePlaceholders" value="true" />
</bean>
我目前拥有的代码片段如下所示:
<camel:choice>
<camel:when>
<camel:simple>{{com.example.PropertyKey}} == 'true'</camel:simple>
<camel:to uri="executingTargetAction" />
</camel:when>
<camel:otherwise>
<!-- Empty block so that nothing happens -->
</camel:otherwise>
</camel:choice>
截至目前,这种方法并没有给我想要的结果。
我试过同时使用
<xpath>
和 <spel>
而不是 <simple>
看看它们是否有效,但似乎这些表达式语言都希望条件的左侧包含 Exchange
来自 Camel 路线的对象。我不想将任何内容与 Exchange 对象进行比较——我只想将属性文件中的属性与我提供的给定文字进行比较(在这种情况下,它是 bool 值“true”)。我愿意使用除
<simple>
之外的任何 Camel 表达式语言以及上面列出的将执行此任务的其他人。
最佳答案
您可以在选择和内部时使用 bean 方法。该方法的返回类型将是 bool 值,因此如果返回 true,那么您的代码 when 将被执行,否则将不被执行。
<choice>
<when>
<method ref="ABC" method="pqr" />
-----your desired logic-----
</when>
</choice>
关于spring - 如何在 Spring XML 的 Apache Camel 路由中将属性与( bool 值)文字进行比较?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32573669/