Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring | SPEL多属性访问器_Spring_Spring Boot_Spring El - Fatal编程技术网

Spring | SPEL多属性访问器

Spring | SPEL多属性访问器,spring,spring-boot,spring-el,Spring,Spring Boot,Spring El,我正在尝试将SPeL与多个属性访问器一起使用 StandardEvaluationContext simpleContext = new StandardEvaluationContext(myPojo); simpleContext.setVariable("ctx", ruleExecutionContext); simpleContext.setPropertyAccessors(Arrays.asList(new MapAccessor(), new Re

我正在尝试将SPeL与多个属性访问器一起使用

StandardEvaluationContext simpleContext = new StandardEvaluationContext(myPojo);
        simpleContext.setVariable("ctx", ruleExecutionContext);
        simpleContext.setPropertyAccessors(Arrays.asList(new MapAccessor(), new ReflectivePropertyAccessor()));
        ExpressionParser parser = new SpelExpressionParser();
        return (Boolean) parser.parseExpression(spelExpression).getValue(simpleContext, RulebaseConfiguration.LIB_MAP);
RulebaseConfiguration.LIB_映射包含
{“instanceName”:instance}

我希望传递可以在POJO上操作的表达式以及实例上的调用方法。但它只会让地图生效

我得到这个错误:

SEVERE: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'payload' cannot be found on object of type 'java.util.HashMap' - maybe not public?] with root cause
org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'payload' cannot be found on object of type 'java.util.HashMap' - maybe not public?
    at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:226)
  • 为每个请求创建上下文并解析表达式是浪费的,除非每个请求的上下文不同;在这种情况下,考虑缓存表达式/上下文。

  • 正如我所说,由于您将
    rootObject
    传递给
    getValue()
    ,因此您的
    myPojo
    是“隐藏的”—计算总是在
    LIB\u MAP
    上执行

  • 您需要在没有根对象的情况下调用
    getValue()
    ,才能使用上下文的根对象。您可以添加
    LIB_MAP
    作为变量(例如,使用名称
    nationalylookup
    )并使用


    你需要表现出你的表情和你想做的事情
    getValue(ctx,rootObject)
    覆盖传递到上下文的ctor中的
    rootObject
    。表达式:
    payload['National']=='GBR'
    MyPojo(根对象)有一个名为payload的映射。在其他一些情况下,我也会有这样的表达式:
    payload['channel']==nationalityLookup.resolveChannel('CBR1000'))
    payload['channel'] == #nationalityLookup.resolveChannel('CBR1000')