2011-07-27 28 views
8

我想使用Spring集成来实现基于内容的路由器,如果表达式值与任何映射都不匹配,则使用默认输出通道。这里是我的bean定义:春季集成:基于内容的路由器默认输出通道?

<int:router input-channel="channel_in" default-output-channel="channel_default" expression="payload.name"> 
    <int:mapping value="foo" channel="channel_one" /> 
    <int:mapping value="bar" channel="channel_two" /> 

然而,似乎默认的输出通道从未使用过。如果表达式评估为例如“巴兹”,路由器似乎在寻找,而不是路由到“channel_default”频道名为“巴兹”通道:

org.springframework.integration.MessagingException: failed to resolve channel name 'baz' 
    Caused by: org.springframework.integration.support.channel.ChannelResolutionException: 
    failed to look up MessageChannel bean with name 'baz' 
    Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: 
    No bean named 'baz' is defined 

是我想在所有可能使用XML命名空间,还是我需要编写我自己的实现?

回答

9

原来,我不得不这样来使这项工作是设置路由器的忽略频道名称,分辨率故障属性设置为false:

<int:router input-channel="channel_in" default-output-channel="channel_default" 
    expression="payload.name" ignore-channel-name-resolution-failures="true"> 
    <int:mapping value="foo" channel="channel_one" /> 
    <int:mapping value="bar" channel="channel_two" /> 
</int:router> 

我想我之前曾经尝试过,但我似乎没有。

+10

如果您正在阅读Spring Integration 2.1+,忽略了通道名称解析失败。您可以通过使用resolution-required =“false”来获得相同的效果。请参阅http://static.springsource.org/spring-integration/reference/htmlsingle/#2.1-router-standardization – Joe