问题
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']
gives you the value of the entry having the String 'my-key' as key.
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
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?
回答1:
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.
来源:https://stackoverflow.com/questions/45512177/spring-integration-expression-map-access-with-dot-notation