gpt4 book ai didi

java - Spring Integration Mail - 将 XML 转换为 Java Config

转载 作者:行者123 更新时间:2023-11-29 08:42:53 25 4
gpt4 key购买 nike

我是 Spring Framework 的新手,我在将 *.xml 转换为 Java Config 时遇到了一些麻烦。我不知道该如何替换这一行:

<int:channel id="emails"/>

你可以在下面看到我的文件

xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/mail http://www.springframework.org/schema/integration/mail/spring-integration-mail.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-mail="http://www.springframework.org/schema/integration/mail"
xmlns:util="http://www.springframework.org/schema/util">

<int:channel id="emails"/>

<util:properties id="javaMailProperties">
<prop key="mail.imap.socketFactory.class">javax.net.ssl.SSLSocketFactory</prop>
<prop key="mail.imap.socketFactory.fallback">false</prop>
<prop key="mail.store.protocol">imaps</prop>
<prop key="mail.debug">true</prop>
</util:properties>

<int-mail:imap-idle-channel-adapter id="mailAdapter"
store-uri="imaps://login:pass@imap-server:993/INBOX"
java-mail-properties="javaMailProperties"
channel="emails"
should-delete-messages="false"
should-mark-messages-as-read="true">
</int-mail:imap-idle-channel-adapter>
</beans>

我已经创建的 Java 配置:

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.mail.ImapIdleChannelAdapter;
import org.springframework.integration.mail.ImapMailReceiver;

import java.util.Properties;

@Configuration
class ImapConfiguration {

private Properties javaMailProperties() {
Properties javaMailProperties = new Properties();

javaMailProperties.setProperty("mail.imap.socketFactory.class","javax.net.ssl.SSLSocketFactory");
javaMailProperties.setProperty("mail.imap.socketFactory.fallback","false");
javaMailProperties.setProperty("mail.store.protocol","imaps");
javaMailProperties.setProperty("mail.debug","true");

return javaMailProperties;
}

@Bean
ImapIdleChannelAdapter mailAdapter() {
ImapMailReceiver mailReceiver = new ImapMailReceiver("imaps://login:pass@imap-server:993/INBOX");

mailReceiver.setJavaMailProperties(javaMailProperties());
mailReceiver.setShouldDeleteMessages(false);
mailReceiver.setShouldMarkMessagesAsRead(true);

return new ImapIdleChannelAdapter(mailReceiver);
}
}

最佳答案

I don't know how should I replace this line:

<int:channel id="emails"/>

刚好

@Bean
public MessageChannel emails() {
return new DirectChannel();
}

请阅读Reference Manual了解更多信息并查看 samples项目。

是的,不要忘记您的一些@Configuration 类的@EnableIntegration:http://docs.spring.io/spring-integration/reference/html/overview.html#programming-tips

关于java - Spring Integration Mail - 将 XML 转换为 Java Config,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38880361/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com