mail:inbound-channel-adapter返回类型

时间:2018-05-03 11:30:51

标签: spring-integration

我正在使用Java注释和ImapIdleChannelAdapter设置 mail:inbound-channel-adapter

目前尚不清楚从@InboundChannelAdapter传递到@ServiceActivator的对象类型。

代码段:

@InboundChannelAdapter(value = "inputChannel", poller = @Poller(fixedDelay = "5000"))
public ImapIdleChannelAdapter getMailAdapter() {
    ImapMailReceiver mailReceiver = new ImapMailReceiver("imaps://username:password@map-mail.outlook.com:993/INBOX");
    ...
    return new ImapIdleChannelAdapter(mailReceiver);
}

@ServiceActivator(inputChannel = "inputChannel")
public void readMessage(Message<javax.mail.Message> message) {
    System.out.println(message.getPayload().getAllRecipients());
}

ImapIdleChannelAdapter来源说&#34; Message有效负载将是收到的javax.mail.Message实例&#34;。不过,在运行上面的代码时,我收到了一个类强制转换异常ImapIdleChannelAdapter cannot be cast to javax.mail.Message

如果我将SA的方法参数更改为javax.mail.Message,我将获得spel.SpelEvaluationException: EL1004E: Method call cannot be found on .. type

@ServiceActivator(inputChannel = "inputChannel")
public void readMessage(javax.mail.Message message) throws MessagingException {
    System.out.println(message.getAllRecipients());
}

1 个答案:

答案 0 :(得分:0)

ImapIdleChannelAdapter是一个事件驱动的组件。它不是民意调查的来源。它将通过自己的内部任务生成消息。

您必须从其配置中删除@InboundChannelAdapter并添加简单的@Beanchannel必须直接配置一个ImapIdleChannelAdapter对象。