【问题标题】:how to use SFTP Outbound Gateway 'mget' command to download files?如何使用 SFTP Outbound Gateway 'mget' 命令下载文件?
【发布时间】:2018-03-24 06:28:02
【问题描述】:

我想使用 'mget' 命令从 sftp 服务器下载文件。这是我的 java 配置:

    @Bean
public SessionFactory<ChannelSftp.LsEntry> sftpSessionFactory() {
    DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(true);
    ....
    return new CachingSessionFactory<>(factory);
}



@Bean(name = "lsGateway")
@ServiceActivator(inputChannel = "sftpChannel")
public MessageHandler handlerLs() {
    // call 'mget' command to download all the files in server folder
    SftpOutboundGateway sftpOutboundGateway = new  SftpOutboundGateway(sftpSessionFactory(), "mget", "payload");
    sftpOutboundGateway.setLocalDirectory(new File("/local/path"));
    return sftpOutboundGateway;

}

网关接口:

@MessagingGateway
public interface OutboundGatewayOption {
@Gateway(requestChannel = "sftpChannel")
 List<File> mget(String dir);

}

执行下载:

@Component
public class Step1Tasklet implements Tasklet {

@Autowired
private OutboundGatewayOption gatewayOption;

@Override
public RepeatStatus execute(StepContribution stepContribution,
        ChunkContext chunkContext) throws Exception {

    // download  files in server folder
    List<File> files = gatewayOption.mget("/ftp/server/path/");


    return RepeatStatus.FINISHED;
}

}

我遇到了这个异常:

 org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'sftpChannel' available

我用谷歌搜索了,但没有找到问题,请有人帮忙!

【问题讨论】:

    标签: spring-integration


    【解决方案1】:

    没有名为“sftpChannel”的bean

    表示你还没有 sftpChannel MessageChannel bean。

    我认为问题来自@MessagingGateway bean 定义。

    你需要做的只是声明sftpChannel bean:

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

    好的,在最新的 Spring Integration 中,这个问题已经得到修复,MessageChannel 最近根据需要从它的名称中解决了。

    【讨论】:

    • 嗨@Artem,我添加了`@Bean(name = "sftpChannel") public MessageChannel sftpChannel() { return new DirectChannel(); }` 但它仍然:没有名为 'sftpChannel' 的 bean
    • 我的 spring-integration-sftp 版本 5.0.5
    • 嗯,没有这样的版本。我猜可能是4.0.5。不过考虑升级到最新版本:projects.spring.io/spring-integration。另外,请分享有关该错误的更多堆栈跟踪。还有一个愚蠢的问题:你真的有@EnableIntegration 吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-14
    • 2022-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多