春天收到没有xml的电子邮件(仅使用注释) [英] spring receive emails without xml (using annotations only)

查看:229
本文介绍了春天收到没有xml的电子邮件(仅使用注释)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要定期检查约30个邮箱,并希望仅使用注释。我知道如何使用XML文件,它看起来像这样:

I need to periodically check about 30 mailboxes and want to do this with annotations only. I know how to do it with XML files, it looks like this:

<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"/>

>但我不知道如何使用它。其实我在春天是新的,所以任何帮助非常感谢!

I know that Spring 4+ have @InboundChannelAdapter but I dont know how to use it. Actually I am new in Spring, so any helps very appreciated!

推荐答案

您正在寻找正确的方式 - @InboundChannelAdapter 。如果您查看文档正确,你会看到这样的:

You are looking into the correct way - @InboundChannelAdapter. If you take a look to the Documentation properly, you'll see something like this:

@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 为您的 EmailReceiverService

and so with other @Beans for MessageChannel and @ServiceActivator for your EmailReceiverService.

考虑作为Java配置的工具 Spring Integration Java DSL

Consider as a tool for Java Configuration the Spring Integration Java DSL.

这篇关于春天收到没有xml的电子邮件(仅使用注释)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆