Spring Integration接收邮件错误的解决方法

来源:爱站网时间:2022-02-22编辑:网友分享
当出现Spring Integration接收邮件发生错误的提示时,我们应该用怎么样方法来解决比较好呢?带着问题,爱站技术频道小编在此整理了相关问题,感兴趣就看看吧!

问题描述


我在Spring Integration中有一个简单的项目正在尝试接收邮件:

@Service
public class MailReceiverService implements CommandLineRunner {

    @Bean
    TestMailServer.ImapServer imapServer() {
        return TestMailServer.imap(0);
    }

    private static Log logger = LogFactory.getLog(MailReceiverService.class);

    public static void manageMessage() {

    @SuppressWarnings("resource")
    ClassPathXmlApplicationContext ac =
        new ClassPathXmlApplicationContext(
            "/integration/gmail-imap-idle-config.xml");
    DirectChannel inputChannel = ac.getBean("receiveChannel", DirectChannel.class);


            inputChannel.subscribe(message -> {
                logger.info("Message: " + message);
            });



  }

    @Override
    public void run(String... args) {
        manageMessage();
    }


}

gmail-imap-idle-config.xml看起来像这样:

javax.net.ssl.SSLSocketFactoryfalseimapsfalse

但是,当我运行它时,我收到此消息:

Channel'application.errorChannel'具有0个订阅者。停止了bean'_org.springframework.integration.errorLogger'

它关闭了!关于如何使它工作的任何建议?谢谢!

思路:


您没有使应用程序保持活动状态的问题。 在后台启动一个长时间运行的进程。但是,当您启动应用程序时,您会立即离开主线程,然后退出。同时,您从电子邮件框中收到一条消息,但是receiveChannel的订阅者已经走了,因为根据主线程的行为,您的应用程序处于关闭状态。

考虑到某些障碍,因为run()不会退出主线程。

在示例中,我们通常有这样的内容:

System.out.println("Hit 'Enter' to terminate");
System.in.read();
ctx.close();

这样,您将不会让JVM退出,因此将在您终止应用程序之前接收电子邮件。

Spring Integration接收邮件错误的解决方法就先分享到这里了,如果你还有更好的提议,随时可以来爱站技术频道网站给小编留言。

上一篇:Java编程中csv和xml是不是雷同

下一篇:javascript怎么将Blob作为对象使用

您可能感兴趣的文章

相关阅读

热门软件源码

最新软件源码下载