These are my configurations :
SftpPoller
DataPackageHandler<TI, TO, T, TD>
FtpConfiguration
@Configuration
public class SftpPoller{
@Autowired
SftpInboundFileSynchronizer sFtpInboundFileSynchronizer;
@Bean
@InboundChannelAdapter(value = "receiveChannel",poller = @Poller(fixedRate = "1000",maxMessagesPerPoll = "1"))
MessageSource<File> pollFtpForFiles() {
SftpInboundFileSynchronizingMessageSource messageSource = new SftpInboundFileSynchronizingMessageSource(sFtpInboundFileSynchronizer);
messageSource.setLocalDirectory(new File("local-dir"));
messageSource.setAutoCreateLocalDirectory(true);
return messageSource;
}
@Bean
PollableChannel receiveChannel() {return new QueueChannel();}
}
SftpInboundReceiveSample.java
@Configuration
@ImportResource("META-INF/spring/integration/SftpSampleCommon.xml")
@PropertySource("classpath:/application.properties")
public class SftpConfiguration {
@Autowired
@Qualifier("serverPort")
String serverPort;
@Value("${privateKeyfile}")
Resource privateKeyfile;
...
@Bean
DefaultSftpSessionFactory defaultSftpSessionFactory() {
DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory();
factory.setHost(host);
factory.setPrivateKey(privateKeyfile);
factory.setPrivateKeyPassphrase(passphrase);
.....
return factory;
}
@Bean
CachingSessionFactory cachingSessionFactory(DefaultSftpSessionFactory defaultSftpSessionFactory) {
return new CachingSessionFactory(defaultSftpSessionFactory);
}
@Bean
SftpInboundFileSynchronizer sftpInboundFileSynchronizer(CachingSessionFactory cachingSessionFactory) {
final SftpInboundFileSynchronizer sftpInboundFileSynchronizer = new SftpInboundFileSynchronizer(cachingSessionFactory);
sftpInboundFileSynchronizer.setRemoteDirectory("remote-dir");
sftpInboundFileSynchronizer.setDeleteRemoteFiles(false);
return sftpInboundFileSynchronizer;
}
}
Question :
@Test
public void runDemo() {
//load context
AnnotationConfigApplicationContext context =
new AnnotationConfigApplicationContext(SftpConfiguration.class, SftpPoller.class);
....
try{
PollableChannel localFileChannel =
context.getBean("receiveChannel", PollableChannel.class);
....
// cant find SourcePollingChannelAdapter
SourcePollingChannelAdapter adapter =
context.getBean(SourcePollingChannelAdapter.class); -
adapter.start();
....
}
or should I look for different 'PollingChannelAdapter' ?thank you for any help and assistance.
答案 0 :(得分:1)
您必须在@EnableIntegration
上添加@Configuration
。这是引导Spring Integration基础架构的主要注释。
由于SourcePollingChannelAdapter
缺席,@EnableIntegration
不存在。
看起来你已经在Java Config中做了所有事情! : - )
您甚至可以将SftpSampleCommon.xml
移动到Java Config。
请阅读有关Spring Integration Annotation Support的更多信息,并注意Spring Integration Java DSL项目。