i try to change from xml to programatically configuration one example from spring-boot integration which is SftpInboundReceiveSample
These are my configurations :
SftpPoller
@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();}
}
FtpConfiguration
@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;
}
}
SftpInboundReceiveSample.java
@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();
....
}
Question :
SourcePollingChannelAdapter or should I look for different 'PollingChannelAdapter' ?thank you for any help and assistance.
You have to add @EnableIntegration on the @Configuration. That's is the main annotation to bootstrap Spring Integration infrastructure.
The SourcePollingChannelAdapter doesn't exist because of the @EnableIntegration absence.
Looks like you already did everything in the Java Config! :-)
You even can move that SftpSampleCommon.xml to the Java Config as well.
Please, read more about Spring Integration Annotation Support and pay attention to the Spring Integration Java DSL project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With