使用Spring-Integration Gemfire支持时SpEL出错

时间:2014-04-25 10:56:15

标签: expression spring-integration spring-el gemfire

我正在使用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'

2 个答案:

答案 0 :(得分:1)

您无法在该表达式中使用payload - 目前还没有消息;根据XSD文档,该表达式是&#34;要计算表达式以生成有效负载的值。&#34;。

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

如果您想将整个事件传递到您的函数中,请使用#root

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

或者您可以执行类似

的操作

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

答案 1 :(得分:0)

您的问题是针对SpEL功能的错误引用。应该是

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

我和simbol #而不是@。请查看SpEL Reference

@用于bean引用,但#用于SpEL函数。