【问题标题】:Apache Camel -- Reference type constants in Spring DSLApache Camel——Spring DSL 中的引用类型常量
【发布时间】:2015-11-12 09:06:26
【问题描述】:

我正在尝试使用 Spring DSL 为 Hazelcast 主题定义发布操作

<from uri="direct:inbound" />      
        <onCompletion>
            <log message="onCompletion:- ${body}" />
            <setHeader headerName="${type:org.apache.camel.component.hazelcast.HazelcastConstants.OPERATION}">
                <simple>${type:org.apache.camel.component.hazelcast.HazelcastConstants.PUBLISH_OPERATION}</simple>
            </setHeader>
            <to uri="hazelcast:topic:foo" />
        </onCompletion>                                                
        <log message="${body}" />

上述路线有效,但我必须使用像“${type:org.apache.camel.component.hazelcast.HazelcastConstants.OPERATION}”这样的长简单脚本来引用常量值。有没有更简单或简短的形式?

我尝试为 HazelcastConstants 类定义一个 spring bean,并通过如下简单脚本引用它,但它不适用于 MethodNotFoundException "Method with name: OPERATION not found on bean"

<bean id="hazelcastConstants" class="org.apache.camel.component.hazelcast.HazelcastConstants" />
... ...
<simple>${bean:hazelcastConstants.OPERATION}</simple>

【问题讨论】:

    标签: spring apache-camel hazelcast


    【解决方案1】:

    如果您定义的 bean 包含返回相关常量的方法,那么您的 bean 解决方法将起作用,例如:

    public class ContantRetriever() {
      public String getHazelCastOperation() {
       return org.apache.camel.component.hazelcast.HazelcastConstants.PUBLISH_OPERATION;
      }
    }
    

    你的 Spring 上下文:

    <bean id="hazelcastConstants" class="yourpackage.ContantRetriever"/>
    <simple>${bean:hazelcastConstants.getHazelCastOperation}</simple>
    

    如果这对你没有好处,恐怕你会被访问常量的长形式所困扰。

    【讨论】:

      猜你喜欢
      • 2017-02-19
      • 1970-01-01
      • 2016-05-05
      • 1970-01-01
      • 2020-08-30
      • 1970-01-01
      • 1970-01-01
      • 2017-07-25
      • 1970-01-01
      相关资源
      最近更新 更多