0
我的spring批处理项目需要从多个sftp服务器下载文件。 sftp主机/端口/文件路径配置在application.properties文件中。我考虑使用Spring集成的'ftp out-bound gateway'来连接这些服务器并下载文件。但我不知道如何做这种配置(我使用java配置,)并使其工作?我想我需要一些方法来定义多个会话工厂根据在application.properties文件中的sftp服务器信息配置的数量。春季集成:连接多台sftp服务器的解决方案/技巧?
属性文件:
sftp.host=host1,host2
sftp.user=user1,user2
sftp.pwd=pwd1,pwd2
配置类:
@Bean
public SessionFactory<ChannelSftp.LsEntry> sftpSessionFactory1() {
...
}
@Bean(name = "myGateway1")
@ServiceActivator(inputChannel = "sftpChannel1")
public MessageHandler handler1() {
...
}
@MessagingGateway
public interface DownloadGateway1 {
@Gateway(requestChannel = "sftpChannel1")
List<File> start(String dir);
}
@Bean(name="sftpChannel1")
public MessageChannel sftpChannel1() {
return new DirectChannel();
}
喜加里,我想设置与@注释一个类中的多个SFTP连接组态。连接信息是配置在属性文件中,我奋斗很长时间,但不能实现它,你可以提供一些提示?谢谢! [也见这篇文章](https://stackoverflow.com/questions/46802260/how-to-define-multiple-sftp-connections) –
目前尚不清楚问题是什么;您可以在@ Configuration中轻松添加多个连接工厂,作为'@ Bean's,每个连接工厂都有自己的一组属性。如果那不是你的意思;请详细解释一下。 –
嗨加里,我无法静态定义多个@Bean,因为连接的数量取决于属性文件。这些bean应该动态地注册到spring上下文中。 –