Spring integration 如何在java配置中使用Spring集成sftp出站网关
我是Spring integration sftp的新手。现在,我想从多个目录下载文件。看来sftp出站网关是我的首选,但我只找到使用XML配置的示例。如何使用Java配置实现这一点? 我的配置类:Spring integration 如何在java配置中使用Spring集成sftp出站网关,spring-integration,spring-integration-sftp,Spring Integration,Spring Integration Sftp,我是Spring integration sftp的新手。现在,我想从多个目录下载文件。看来sftp出站网关是我的首选,但我只找到使用XML配置的示例。如何使用Java配置实现这一点? 我的配置类: @Configuration public class SftpConfig { @Bean public SessionFactory<LsEntry> sftpSessionFactory(){ DefaultSftpSessionFactory de
@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);
}
不清楚你所说的“什么都没发生”是什么意思。您似乎有两种方式触发LS请求—消息网关(您必须调用)和入站通道适配器(具有
autoStartup=“false”
),它在启动网关之前不会调用网关
此外,当将其用作触发器时,您将需要SFTP网关上的输出通道(将结果发送到哪里)。通过调用消息网关调用网关时,结果将返回到网关(因为SFTP网关没有输出通道)。是的,当我没有使用LS网关时,我使用messageSource.receive()接收文件。但是当我使用LS网关时,我不知道如何接收文件。而且OutboundGateway选项似乎不起作用。当我在配置类中使用@Autowire时,我无法获取bean。我如何使用它作为触发器?请参阅我的答案-它是ftp而不是sftp,但同样适用;它有额外的逻辑来限制获取的文件数量。很抱歉,很晚才回复,当我自动连接OutboundGateway选项时,我得到了一个NoSuchBeanDefinitionException。现在我没有IntegrationFlow Bean,这有关系吗?在5.0中,它将被集成;对于早期版本,您需要一个附加依赖项:
org.springframework.integration;spring integration java dsl:1.2.1.RELEASE
。现在我在pom.xml中有了spring integration java dsl依赖项。在我的测试类中,我自动连接了OutboundGateway,但我没有找到依赖项[com.creditcloud.calculator.config.OutboundGatewayOption]类型的合格bean,似乎我没有把它定义为Bean?但是在你给我的链接中,它是有效的。哪里错了?
@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("/");
}
}