这应该是一个简单的问题,但我在网上找不到合适的文档。我想做这个:
@MessagingGateway(name = "redemptionGateway", defaultRequestChannel = Channels.GATEWAY_OUTPUT, defaultHeaders = @GatewayHeader(name = "orderId", expression = "#redemption.orderId"))
public interface RedemptionGateway {
void create(TrivialRedemption redemption);
}
我显然使用了错误的陈述来引用orderId
成员redemption
:
org.springframework.expression.spel.SpelEvaluationException: EL1007E:(pos 0): Property or field 'orderId' cannot be found on null
OK. Look
@GatewayHeader(name = "orderId", expression = "#redemption.orderId")
此 SpEL 在运行时根据构建的实际参数进行评估MessageHeaders
对于目标Message
发送。
这就是它的样子:
private StandardEvaluationContext createMethodInvocationEvaluationContext(Object[] arguments) {
StandardEvaluationContext context = ExpressionUtils.createStandardEvaluationContext(this.beanFactory);
context.setVariable("args", arguments);
context.setVariable("gatewayMethod", this.method);
return context;
}
So, EvaluationContext
富含两个变量args
and gatewayMethod
.
如您所见,没有任何参数按其名称填充。这对所有 JVM 都适用吗?
您可以使用以下参数索引来实现您的目标args
:
expression = "#args[0].orderId"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)