Spring | SPEL多属性访问器
我正在尝试将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
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')