2

我是 Spring 集成 sftp 的新手。现在,我想从多个目录下载文件。然后似乎 SFTP 出站网关是我的选择,但我只找到使用 XML 配置的示例。如何使用 Java 配置来完成?我的配置类:

@Configuration
public class SftpConfig {
    @Bean
    public SessionFactory<LsEntry> sftpSessionFactory(){
        DefaultSftpSessionFactory defaultSftpSessionFactory = new DefaultSftpSessionFactory();
        ...
        return new CachingSessionFactory<LsEntry>(defaultSftpSessionFactory);
    }
    @Bean
    @InboundChannelAdapter(channel = "sftpChannel",autoStartup = "false", poller = @Poller(fixedDelay = "5000"))
    public MessageSource<File> sftpMessageSource() {
    ...
    }
    @Bean(name = "lsGateway")
    @ServiceActivator(inputChannel = "sftpChannel")
    public MessageHandler handlerLs(){
        SftpOutboundGateway sftpOutboundGateway = new SftpOutboundGateway(sftpSessionFactory(),"ls","payload");
        sftpOutboundGateway.setLocalDirectory(new File("sftp-gateway"));
        return sftpOutboundGateway;
    }
}

@MessagingGateway
public interface OutboundGatewayOption {
    @Gateway(requestChannel = "sftpChannel")
    public List<Boolean> lsGetAndRmFiles(String dir);

}

但是当我启动应用程序时,没有任何反应,哪里出错了?

----更新---我的测试班

@SpringBootTest(classes = Application.class)
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@Configuration
@EnableIntegration
@Slf4j
@MessageEndpoint
public class SftpConfigTest{
    @Autowired
    private OutboundGatewayOption gatewayOption;
    @Test
    public void test(){
        gatewayOption.lsGetAndRmFiles("/");
    }
}
4

1 回答 1

2

目前尚不清楚您所说的“什么都没有发生”是什么意思。看来您有两种触发 LS 请求的方法 - 一个消息传递网关(您必须调用它)和一个入站通道适配器,它有autoStartup = "false"- 在网关启动之前它不会调用网关。

此外,当使用它作为触发器时,您将需要 SFTP 网关上的输出通道(发送结果的位置)。通过调用消息网关调用网关时,结果将返回给网关(因为SFTP网关没有输出通道)。

于 2017-03-31T12:55:22.943 回答