我是 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("/");
}
}