Spring 集成表达式映射访问与点表示法 [英] Spring integration expression map access with dot notation

查看:46
本文介绍了Spring 集成表达式映射访问与点表示法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常在 Spring EL 中,您可以使用方括号中的键通过键访问映射条目.如果 spring 集成消息的负载是 java.util.Map,则

Normally in Spring EL you access a map entry by its key using the key in square brackets. If the payload of a spring integration message is a java.util.Map, then

payload['mykey'] 

为您提供以字符串my-key"作为键的条目的值.

gives you the value of the entry having the String 'my-key' as key.

使用标准 Spring EL 设置时,例如在单元测试中,这是使用地图的唯一方法.但是,在 Spring 集成流使用的表达式中,我可以使用点表示法进行映射访问.这有效:

When using the standard Spring EL setup, e.g. in a unit test, that is the only way to work with the map. However, in expressions used by Spring integration flows I can use the dot notation for map access. This works:

payload.mykey

我希望能够在单元测试和路由定义中使用相同的 Spring EL 表达式.是什么使 Spring 集成中的点符号成为可能?我是否必须对 EL 解析器应用一些特殊选项?

I want to be able to use the same Spring EL expressions both in unit tests and route definitions. What makes the dot notation possible in Spring integration? Do I have to apply some special option to the EL parser?

推荐答案

我在 找到了答案Spring 表达式语言的映射.我需要添加一个 http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/expression/MapAccessor.html 到评估上下文.

I found the answer at Map for spring expression language. I need to add a http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/expression/MapAccessor.html to the evaluation context.

这篇关于Spring 集成表达式映射访问与点表示法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆