如何定义多个sftp连接? [英] how to define multiple sftp connections?

查看:12
本文介绍了如何定义多个sftp连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用出站网关从多个sftp服务器下载文件,sftp服务器的数量在属性中配置(这意味着我需要动态定义连接), 我的应用程序.属性:

sftp.host=host1,host2
sftp.user=user1,user2
sftp.pwd=pwd1,pwd2

当前我使用Java配置为:

@Configuration

公共类SFtpConfig{

static  Logger logger = LoggerFactory.getLogger(SFtpConfig.class);

@Autowired
SftpServerProperties sftpServerProperties;

@Autowired
SftpClientProperties sftpClientProperties;

@Bean
public SessionFactory<ChannelSftp.LsEntry> sftpSessionFactory() {

 ...
}

@Bean(name = "myGateway")
@ServiceActivator(inputChannel = "sftpChannel")
public MessageHandler handlerLs() {

 ...
}

@MessagingGateway
public interface DownloadGateway {
    @Gateway(requestChannel = "sftpChannel")
    List<File> start(String dir);
}

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

}
但此配置仅用于连接到一个sftp服务器,那么如何使用Application.Properties配置定义多个sftp连接? 我指的是会话工厂/处理程序/网关/Channer的动态数量(有些Bean有注释,如何动态定义这种Bean?)

推荐答案

您应该考虑为ConnectionFactories声明具有相同内容但不同属性的子ApplicationContext

/**
 * Set the parent of this application context.
 * <p>Note that the parent shouldn't be changed: It should only be set outside
 * a constructor if it isn't available when an object of this class is created,
 * for example in case of WebApplicationContext setup.
 * @param parent the parent context
 * @see org.springframework.web.context.ConfigurableWebApplicationContext
 */
void setParent(@Nullable ApplicationContext parent);

这篇关于如何定义多个sftp连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆