无法在Spring路由器中使用SpEL路由到Message端点

时间:2016-07-15 09:37:11

标签: spring spring-integration

我有一个message-driven-channel-adapter正在侦听jms队列'inputqueue',应用程序正在以下面的格式发布json消息。

{
 "name": "Praveep",
 "action": "Drink",
 "age": "32",
 "userid": "pk",
 "details": [{
    "state": "karnataka",
    "country": "India",
  }]
}

在我的applicationContext文件中,我定义了router,根据操作将消息指向适当的队列。

<int:channel id="processEmpChannel">
    <int:queue />
</int:channel>

<int:channel id="drink">
    <int:queue />
</int:channel>

<int:channel id="eat">
    <int:queue />
</int:channel>

<int:channel id="sleep">
    <int:queue />
</int:channel>


<int:router input-channel="processEmpChannel" expression="$.action">
    <int:mapping value="drink" channel="drink" />
    <int:mapping value="eat" channel="eat" />
    <int:mapping value="sleep" channel="sleep" />
</int:router>

<int:service-activator input-channel="drink"
    ref="springExample" method="handleDrink">
    <int:poller ref="poller"></int:poller>
</int:service-activator>

<int:service-activator input-channel="eat"
    ref="springExample" method="handleEat">
    <int:poller ref="poller"></int:poller>
</int:service-activator>

<int:service-activator input-channel="sleep"
    ref="springExample" method="handleSleep">
    <int:poller ref="poller"></int:poller>
</int:service-activator>

在我的类文件中,我为公共方法中的每个操作定义了方法。当我运行java程序时,我收到以下错误。有人可以告诉我spel表达中我出错的地方。

Property or field '$' cannot be found on object of type 'org.springframework.messaging.support.GenericMessage' - maybe not public?

1 个答案:

答案 0 :(得分:0)

JSON属性访问者是not configured by default,添加:

<int:spel-property-accessors>
    <bean id="jsonPropertyAccessor" class="org.springframework.integration.json.JsonPropertyAccessor"/>
</int:spel-property-accessors>