无法访问spring集成路由器int中的标头值:映射值

时间:2018-03-16 18:22:01

标签: spring-integration

无法使用下面的

访问路由器的value属性中的标头
<int:router input-channel="route_profile"  expression="#jsonPath(payload, '$.entity')">
        <int:mapping value="headers.userId" channel="toWeb_send"/>
        <int:mapping value="headers.otherId" channel="find_preferences"/>
    </int:router>

这里的任何事我都做错了。

1 个答案:

答案 0 :(得分:1)

表达式不是value属性中预期的表达式:

 <xsd:attribute name="value" type="xsd:string">
      <xsd:annotation>
          <xsd:documentation>
            A value of the evaluation token that will be mapped to a channel reference
            (e.g., mapping value='foo' channel='myChannel')
            </xsd:documentation>
        </xsd:annotation>
 </xsd:attribute>

value正是所提到的顶级expression返回的内容。

因此,让我们对您的expression="#jsonPath(payload, '$.entity')"进行成像可能会返回foobar,因此映射必须如下:

<int:mapping value="foo" channel="toWeb_send"/>
<int:mapping value="bar" channel="find_preferences"/>

如果这些标题周围有一些逻辑,则必须将它们包含在表达式评估中。或者您可以选择其他方式来计算路由密钥。