如何将基于 xml 的 spring-integration-email 配置转换为基于 java 的配置? [英] How to covert xml based spring-integration-email configuration to java based config?
问题描述
我在 Spring Boot 应用程序中使用 spring-integration-email 来接收电子邮件.我在网上找到的所有示例都使用基于 xml 的配置.
I am using spring-integration-email in a spring boot application to receive emails. All example I found online use xml based config.
我在我的应用程序中使用基于 Java 的配置,我想在 spring-integration-email 中使用相同的配置.
I am using java based config in my application and I want to use the same for the spring-integration-email.
下面是我的基于 xml 的配置,它可以正常工作.如何将其转换为基于 Java 的配置?
Below is my xml based config, which works properly. How Can I convert it to java based config?
<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">${imap.debug}</prop>
</util:properties>
<mail:inbound-channel-adapter id="imapAdapter"
store-uri="${imap.uri}"
channel="recieveEmailChannel"
should-delete-messages="false"
should-mark-messages-as-read="true"
auto-startup="true"
java-mail-properties="javaMailProperties">
<int:poller fixed-delay="${imap.poolerSecondsDelay}" time-unit="SECONDS"/>
</mail:inbound-channel-adapter>
<int:channel id="recieveEmailChannel">
<int:interceptors>
<int:wire-tap channel="logger"/>
</int:interceptors>
</int:channel>
<int:logging-channel-adapter id="logger" level="DEBUG"/>
<int:service-activator input-channel="recieveEmailChannel" ref="emailReceiverService" method="receive"/>
<bean id="emailReceiverService" class="com.sts.app.email.service.EmailService">
</bean>
推荐答案
@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;
}
@Bean
public MailReceiver imapMailReceiver(@Value("imaps://${login}:${pass}@${host}:993/inbox") storeUrl) {
ImapMailReceiver imapMailReceiver = new ImapMailReceiver(storeUrl);
// other setters here
return imapMailReceiver;
}
使用可能如下所示的 Spring Integration Java DSL:
With the Spring Integration Java DSL that may look like:
@Bean
public IntegrationFlow imapMailFlow() {
return IntegrationFlows
.from(s -> s.imap("imap://user:pw@localhost:" + imapPort + "/INBOX")
.searchTermStrategy(this::fromAndNotSeenTerm)
.javaMailProperties(p -> p.put("mail.debug", "false")),
e -> e.autoStartup(true)
.poller(p -> p.fixedDelay(1000)))
.channel(MessageChannels.queue("imapChannel"))
.get();
}
另请参阅问题及其讨论:spring 在没有 xml 的情况下接收电子邮件(仅使用注释)
Also see the question and its discussion: spring receive emails without xml (using annotations only)
这篇关于如何将基于 xml 的 spring-integration-email 配置转换为基于 java 的配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!