spring - 如何在 Spring XML 的 Apache Camel 路由中将属性与( bool 值)文字进行比较?

标签 spring properties routes javabeans choice

我正在尝试使用 Camel 路由来执行基于条件语句的操作;如果该条件为真,则它将执行该操作。但是,如果该条件为假,则不会执行该操作。

条件语句基于从“.properties”文件中提取的属性值。我定义了一个 placeholderPrefixplaceholderSuffix对于 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/

相关文章:

java - 如何获取 Mongo 标准中两个日期值之间的差异?

java - Hibernate一对多关系: can't remove children once parent is removed

java - 无法打开 ServletContext 资源 [/src/main/resources/security-context.xml]

c# - C# 属性可以使程序运行速度变慢吗?

angular - 子路由不起作用,应用程序重定向到 404 页面

node.js - Express 中的根路由未重定向

java - 如何在 Spring 中将一些文本添加到所有 Controller URL

javascript - 获取多级javascript对象属性的简单方法

c# - 如何使用自定义属性属性对类的属性进行排序

reactjs - 使用 nextjs 自定义路由?