RecipientListRouter配置

时间:2016-02-15 07:38:15

标签: spring-integration

我正在尝试使用以下代码在Spring-Boot项目中配置RecipientListRouter:

@Bean
public RecipientListRouter locateIncomingCompleteRouter(){
    RecipientListRouter router = new RecipientListRouter();
    router.addRecipient("c1");
    router.addRecipient("c2");
    List<MessageChannel> channels = new ArrayList<MessageChannel>();
    channels.add(c3());
    router.setChannels(channels);
    return router;
}

我收到了以下错误

Caused by: java.lang.IllegalArgumentException: BeanFactory must not be null
at org.springframework.util.Assert.notNull(Assert.java:115) ~[spring-core-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.integration.support.channel.BeanFactoryChannelResolver.<init>(BeanFactoryChannelResolver.java:75) ~[spring-integration-core-4.2.4.RELEASE.jar:na]
at org.springframework.integration.context.IntegrationObjectSupport.getChannelResolver(IntegrationObjectSupport.java:185) ~[spring-integration-core-4.2.4.RELEASE.jar:na]
at org.springframework.integration.router.RecipientListRouter.addRecipient(RecipientListRouter.java:161) ~[spring-integration-core-4.2.4.RELEASE.jar:na]

1 个答案:

答案 0 :(得分:1)

addRecipients用于在创建bean之后动态添加收件人,而不是在bean创建过程中。

要使用@Bean定义连接收件人,请使用

public void setChannels(List<MessageChannel> channels)

public void setRecipients(List<Recipient> recipients)

您需要参考实际频道;不只是他们的名字。