0

我正在使用 Spring-Integration 3.0 和 Spring-Integration Gemfire 支持。我希望我的入站通道适配器根据 SpEL 表达式将缓存中的对象作为有效负载提取。我编写了一个自定义表达式评估器类来检查输入适配器选择的有效负载的属性。类代码如下:

@Component
public class GraphMatchingUtil {

public static boolean evaluate(NodeGraph nodeGraph){
    if(nodeGraph.getLastProcessedTS()!=null){

        if(nodeGraph.getLastProcessedTS().getTime() -  DateTimeUtil.createTimestamp().getTime() > 100000){
            return true;
        }
    }
    else{
        if(nodeGraph.getCreateTS().getTime() -  DateTimeUtil.createTimestamp().getTime() > 100000){
            return true;
        }
    }
    return false;
}

}

配置代码如下

<int:spel-function id="match" class="com.equ.util.GraphMatchingUtil" method="evaluate(com.equ.bo.NodeGraph)"/>
<int-gfe:inbound-channel-adapter id="graphadapter" channel="reconchannel" region="cacheRegion" cache-events="CREATED, UPDATED" expression="@match(payload)==true"/>

但是,执行此代码后出现以下错误:

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'graphadapter': Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'payloadExpression' threw exception; nested exception is org.springframework.expression.spel.SpelParseException: EL1041E:(pos 6): After parsing a valid expression, there is still more data in the expression: 'lparen(()'
     Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
     PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'payloadExpression' threw exception; nested exception is org.springframework.expression.spel.SpelParseException: EL1041E:(pos 6): After parsing a valid expression, there is still more data in the expression: 'lparen(()'

谁能帮我理解它有什么问题?

用#替换@后,我得到了这个错误:

   org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Field or property 'payload' cannot be found on object of type 'com.gemstone.gemfire.internal.cache.EntryEventImpl'
4

2 回答 2

1

您不能payload在该表达式中使用 - 还没有消息;根据 XSD 文档,该表达式是“要评估以生成有效负载值的表达式。”。

我们应该在文档中更清楚地解释这个表达式的根对象是一个 Gemfire EntryEvent这里是 javadocs)。

如果要将整个事件传递到函数中,请使用#root.

expression="#match(#root)==true"

或者你可以做类似的事情

expression="#match(key, oldValue, newValue)==true"

于 2014-04-25T13:00:31.443 回答
0

您的问题是对 SpEL 函数的错误引用。应该

expression="#match(payload)==true"

我的意思是 simbol#而不是@. 请查看SpEL 参考

@用于 bean 参考,但用于#SpEL 功能。

于 2014-04-25T11:11:38.783 回答