Spring boot 无法使RequestHandlerRetryAdvice在Spring集成中与Ftp.outboundGateway一起使用

Spring boot 无法使RequestHandlerRetryAdvice在Spring集成中与Ftp.outboundGateway一起使用,spring-boot,spring-integration,spring-integration-dsl,Spring Boot,Spring Integration,Spring Integration Dsl,我的情况与中描述的类似。区别在于我没有使用WebFlux.outboundGateway而是使用Ftp.outboundGateway调用AbstractRemoteFileOutboundGateway.Command.GET命令,常见的问题是我无法获取要使用的已定义的RequestHandlerRetryAdvice 配置如下所示(分解为相关部分): @RestController @请求映射(value=“/somepath”) 公共类下载控制器 { 私有下载网关下载网关; 公共下载控制器

我的情况与中描述的类似。区别在于我没有使用
WebFlux.outboundGateway
而是使用
Ftp.outboundGateway
调用
AbstractRemoteFileOutboundGateway.Command.GET
命令,常见的问题是我无法获取要使用的已定义的
RequestHandlerRetryAdvice

配置如下所示(分解为相关部分):

@RestController
@请求映射(value=“/somepath”)
公共类下载控制器
{
私有下载网关下载网关;
公共下载控制器(下载网关下载网关)
{
this.downloadGateway=下载网关;
}
@后映射(“/下载”)
公共无效下载(@RequestParam(“filename”)字符串文件名)
{
Map headers=newhashmap();
triggerDownload(文件名、标题);
}
}    
@MessagingGateway
公共接口下载网关
{
@网关(requestChannel=“downloadFiles.input”)
void trigger下载(对象值、映射头);
}
@配置
@使能集成
公共类FtpDefinition
{
私人FtpProperties FtpProperties;
公共FTP定义(FtpProperties FtpProperties)
{
this.ftpProperties=ftpProperties;
}
@豆子
public DirectChannel网关下载soutputchannel()
{
返回新的DirectChannel();
}
@豆子
公共集成流下载文件(RemoteFileOutboundGatewaySpec getRemoteFile)
{
返回f->f.handle(getRemoteFile,getRetryAdvice())
.频道(“网关下载输出频道”);
}

私人消费者很抱歉延迟;我们本周在SpringOne平台

问题是由于网关规范是一个bean的事实——网关在应用通知之前被初始化

我像这样更改了你的代码

@Bean
public IntegrationFlow downloadFiles(SessionFactory<FTPFile> sessionFactory) {
    return f -> f.handle(getRemoteFile(sessionFactory), getRetryAdvice())
            .channel("gatewayDownloadsOutputChannel");
}

...

private RemoteFileOutboundGatewaySpec<FTPFile, FtpOutboundGatewaySpec> getRemoteFile(SessionFactory<FTPFile> sessionFactory) {
    return Ftp.outboundGateway(sessionFactory,
            AbstractRemoteFileOutboundGateway.Command.GET,
            "payload")
            .fileExistsMode(FileExistsMode.REPLACE)
            .localDirectoryExpression("'/tmp'")
            .autoCreateLocalDirectory(true);
}
@Bean
公共集成流下载文件(SessionFactory SessionFactory){
返回f->f.handle(getRemoteFile(sessionFactory),getRetryAdvice())
.频道(“网关下载输出频道”);
}
...
私有RemoteFileOutboundGatewaySpec getRemoteFile(SessionFactory SessionFactory){
返回Ftp.outboundGateway(sessionFactory,
AbstractRemoteFileOutboundGateway.Command.GET,
“有效载荷”)
.fileExistsMode(fileExistsMode.REPLACE)
.localDirectoryExpression(“'/tmp'))
.autoCreateLocalDirectory(true);
}
…而且成功了

一般来说,最好不要直接处理规范,而是将它们内联到流定义中

@Bean
public IntegrationFlow downloadFiles(SessionFactory<FTPFile> sessionFactory) {
    return f -> f.handle(Ftp.outboundGateway(sessionFactory,
            AbstractRemoteFileOutboundGateway.Command.GET,
            "payload")
            .fileExistsMode(FileExistsMode.REPLACE)
            .localDirectoryExpression("'/tmp'")
            .autoCreateLocalDirectory(true), getRetryAdvice())
        .channel("gatewayDownloadsOutputChannel");
}
@Bean
公共集成流下载文件(SessionFactory SessionFactory){
返回f->f.handle(Ftp.outboundGateway(sessionFactory,
AbstractRemoteFileOutboundGateway.Command.GET,
“有效载荷”)
.fileExistsMode(fileExistsMode.REPLACE)
.localDirectoryExpression(“'/tmp'))
.autoCreateLocalDirectory(true),getRetryAdvice()
.频道(“网关下载输出频道”);
}

太棒了,你救了我一天,非常感谢!作为Spring的新手,尤其是Spring集成的新手,我永远不会找到原因和解决方案。
@Bean
public IntegrationFlow downloadFiles(SessionFactory<FTPFile> sessionFactory) {
    return f -> f.handle(Ftp.outboundGateway(sessionFactory,
            AbstractRemoteFileOutboundGateway.Command.GET,
            "payload")
            .fileExistsMode(FileExistsMode.REPLACE)
            .localDirectoryExpression("'/tmp'")
            .autoCreateLocalDirectory(true), getRetryAdvice())
        .channel("gatewayDownloadsOutputChannel");
}