Spring integration 将此Java8DSL转换为非Java8
在使用XML名称空间几年之后,我才开始使用SpringIntegrationDSL 我喜欢DSL,但我缺乏Java8知识,这阻碍了我的发展 例如,您将如何在Java 7中编写以下示例代码,我对Spring integration 将此Java8DSL转换为非Java8,spring-integration,Spring Integration,在使用XML名称空间几年之后,我才开始使用SpringIntegrationDSL 我喜欢DSL,但我缺乏Java8知识,这阻碍了我的发展 例如,您将如何在Java 7中编写以下示例代码,我对e->e.id(“sendMailEndpoint”)感到困惑,因为我无法确定e是什么类型 @Bean public IntegrationFlow sendMailFlow() { return IntegrationFlows.from("sendMailChannel")
e->e.id(“sendMailEndpoint”)
感到困惑,因为我无法确定e
是什么类型
@Bean
public IntegrationFlow sendMailFlow() {
return IntegrationFlows.from("sendMailChannel")
.handle(Mail.outboundAdapter("localhost")
.port(smtpPort)
.credentials("user", "pw")
.protocol("smtp")
.javaMailProperties(p -> p.put("mail.debug", "true")),
e -> e.id("sendMailEndpoint"))
.get();
}
问候
David/David,任何Lambda都是内联功能接口实现。 如果您查看该
.handle()
方法的源代码(或至少是JavaDocs),您将看到e
param是Consumer
,因此对于非Java 8环境,您只需在以下位置实现该接口:
.handle(Mail.outboundAdapter("localhost")
.port(smtpPort)
.credentials("user", "pw")
.protocol("smtp")
.javaMailProperties(p -> p.put("mail.debug", "true")),
new Consumer<GenericEndpointSpec<MailSendingMessageHandler>>() {
@Override
public void accept(GenericEndpointSpec<MailSendingMessageHandler> e) {
e.id("sendMailEndpoint");
}
})
.handle(Mail.outboundAdapter(“localhost”)
.端口(smtpPort)
.凭证(“用户”、“pw”)
.协议(“smtp”)
.javaMailProperties(p->p.put(“mail.debug”,“true”),
新消费者(){
@凌驾
public void accept(GenericEndpointSpec e){
e、 id(“sendMailEndpoint”);
}
})
同样的是
javaMailProperties
谢谢Artem,我确实对Lambda的属性有一些了解,其中一个很好。我遇到的问题是Consumer类和所有Consumer类型的选项,然后是GenericEndpointSpec类型的进一步选项。没问题!请随意询问更多或提供反馈。例如,我要将.aggregate(aggregatorConfigurer,endpointConfigurer)
修改为单个configurer
,它接受AggregatingMessageHandler
及其端点的选项。对于那些特定于协议的规范
,比如Mail.outboundAdapter
,可能同样有意义。