我需要定期检查大约30个邮箱,并且只想使用注释来执行此操作。我知道如何使用XML文件,它看起来像这样:
<mail:inbound-channel-adapter id="ImapAdapter"
store-uri="imaps://${login}:${pass}@${host}:993/inbox"
channel="testReceiveEmailChannel"
should-delete-messages="false"
should-mark-messages-as-read="true"
auto-startup="true"
java-mail-properties="javaMailProperties">
<int:poller fixed-delay="200"
time-unit="SECONDS"
task-executor="asyncTaskExecutor"/>
</mail:inbound-channel-adapter>
<int:channel id="testReceiveEmailChannel">
<int:interceptors>
<int:wire-tap channel="logger"/>
</int:interceptors>
</int:channel>
<int:service-activator input-channel="testReceiveEmailChannel"
ref="testMailReceiverService"
method="receive"/>
<bean id="testMailReceiverService" class="com.myproject.email.EmailReceiverService">
<property name="mailBox" value="${login}"/>
</bean>
<int:logging-channel-adapter id="logger" level="DEBUG"/>
我知道Spring 4+有@InboundChannelAdapter
但我不知道如何使用它。其实我是春天的新人,所以任何帮助都非常感激!
答案 0 :(得分:4)
您正在研究正确的方法 - @InboundChannelAdapter
。如果你正确看一下Documentation,你会看到类似的东西:
@Bean
@InboundChannelAdapter(value = "testReceiveEmailChannel", poller = @Poller(fixedDelay = "200000", taskExecutor = "asyncTaskExecutor"))
public MessageSource<javax.mail.Message> mailMessageSource(MailReceiver mailReceiver) {
MailReceivingMessageSource mailReceivingMessageSource = new MailReceivingMessageSource(mailReceiver);
// other setters here
return mailReceivingMessageSource;
}
其中MailReceiver
是这样的:
@Bean
public MailReceiver imapMailReceiver(@Value("imaps://${login}:${pass}@${host}:993/inbox") storeUrl) {
ImapMailReceiver imapMailReceiver = new ImapMailReceiver(storeUrl);
// other setters here
return imapMailReceiver;
}
以及@Bean
的其他MessageChannel
和@ServiceActivator
的{{1}}。
将Spring Integration Java DSL作为Java配置的工具。