Spring integration Spring FTP集成:如何验证FTP会话?

Spring integration Spring FTP集成:如何验证FTP会话?,spring-integration,spring-integration-sftp,Spring Integration,Spring Integration Sftp,我正在使用以下代码创建ftpSessionfactory- @Bean @Lazy(false) public SessionFactory<FTPFile> ftpSessionFactory() { DefaultFtpSessionFactory sf = new DefaultFtpSessionFactory(); sf.setHost(server); sf.setPort(port); sf.setUsername(username);

我正在使用以下代码创建ftpSessionfactory-

@Bean
@Lazy(false)
public SessionFactory<FTPFile> ftpSessionFactory() {
    DefaultFtpSessionFactory sf = new DefaultFtpSessionFactory();
    sf.setHost(server);
    sf.setPort(port);
    sf.setUsername(username);
    sf.setPassword(password);
    return new CachingSessionFactory<FTPFile>(sf);
}
@Bean
@懒惰(错误)
公共会话工厂ftpSessionFactory(){
DefaultFtpSessionFactory sf=新的DefaultFtpSessionFactory();
设置主机(服务器);
sf.设置端口(端口);
sf.setUsername(用户名);
sf.setPassword(密码);
返回新的CachingSessionFactory(sf);
}
下面的方法检查FTP会话是否正常-

private boolean isFTPSessionOK() {
    try {
        SessionFactory<FTPFile> ftpSessionFactory = ftpSessionFactory();
        boolean open = ftpSessionFactory.getSession().isOpen();
        System.out.println("Session is good ? "+ open);
        return open;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}
私有布尔值isFTPSessionOK(){
试一试{
SessionFactory ftpSessionFactory=ftpSessionFactory();
布尔打开=ftpSessionFactory.getSession().isOpen();
System.out.println(“会话是否良好?”+打开);
返回打开;
}捕获(例外e){
e、 printStackTrace();
}
返回false;
}
有没有其他方法来验证FTP会话而不是编写哑方法


谢谢

好的,是的,如果您已经使用了
CachingSessionFactory
,您就不需要这种方法了


每次执行
ftpSessionFactory.getSession()
pool抽象都会确保向您返回一个有效的、打开的实例。

绝对正确。感谢您提供此功能。然而,若远程主机关闭,或者我们在创建CachingSessionFactory时传递了错误的远程主机,则应用程序不会在日志中报告任何错误,并且我们无法跟踪应用程序是否正常工作。如果ftpSession出现任何问题,是否有任何方法可以在日志中获取通知或错误?请提供建议。由于
CachingSessionFactory
以延迟加载方式工作,因此在启动时确实没有任何钩子来跟踪错误的连接选项。所以,您肯定应该提供家常机制,以便在需要确认时进行验证。那么,你的方法就是很好的选择。