如需使用最新稳定版本,请使用 Spring Integration 7.0.4spring-doc.cadn.net.cn

Apache Mina SFTP 服务器事件

ApacheMinaSftpEventListener(在 5.2 版本中引入)会监听某些 Apache Mina SFTP 服务器事件,并将它们发布为 ApplicationEvent,这些事件可由任何 ApplicationListener Bean、@EventListener Bean 方法或 事件入站通道适配器 接收。spring-doc.cadn.net.cn

目前支持的事件包括:spring-doc.cadn.net.cn

这些类都是 ApacheMinaSftpEvent 的子类;您可以配置一个单一的监听器来接收所有类型的事件。 每个事件的 source 属性是一个 ServerSession,您可以从中获取诸如客户端地址等信息;抽象事件上提供了一个便捷的 getSession() 方法。spring-doc.cadn.net.cn

要使用监听器(必须是一个 Spring bean)配置服务器,只需将其添加到 SftpSubsystemFactory 中:spring-doc.cadn.net.cn

server = SshServer.setUpDefaultServer();
...
SftpSubsystemFactory sftpFactory = new SftpSubsystemFactory();
sftpFactory.addSftpEventListener(apacheMinaSftpEventListenerBean);
...

要使用 Spring Integration 事件适配器来消费这些事件:spring-doc.cadn.net.cn

@Bean
public ApplicationEventListeningMessageProducer eventsAdapter() {
    ApplicationEventListeningMessageProducer producer =
        new ApplicationEventListeningMessageProducer();
    producer.setEventTypes(ApacheMinaSftpEvent.class);
    producer.setOutputChannel(eventChannel());
    return producer;
}