【发布时间】: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
我用谷歌搜索了,但没有找到问题,请有人帮忙!
【问题讨论】: